From 22475b10331ef5ac0445ea264baa9010c6df0468 Mon Sep 17 00:00:00 2001
From: Emmanuel Viennet <emmanuel.viennet@gmail.com>
Date: Sun, 29 Aug 2021 21:21:41 +0200
Subject: [PATCH] =?UTF-8?q?S=C3=A9pare=20les=20tags=20(modules=20et=20item?=
=?UTF-8?q?suivi)=20par=20d=C3=A9partement?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 4 +--
app/models/etudiants.py | 1 +
app/scodoc/sco_debouche.py | 7 ++--
app/scodoc/sco_tag_module.py | 12 +++++--
...b2d0092_scodoc_9_0_5_ajout_dept_id_sur_.py | 32 +++++++++++++++++++
sco_version.py | 2 +-
6 files changed, 50 insertions(+), 8 deletions(-)
create mode 100644 migrations/versions/d3d92b2d0092_scodoc_9_0_5_ajout_dept_id_sur_.py
diff --git a/README.md b/README.md
index 43ce86f8d..12d2bbca8 100644
--- a/README.md
+++ b/README.md
@@ -132,7 +132,7 @@ base de données (tous les départements, et les utilisateurs) avant de commence
On utilise SQLAlchemy avec Alembic et Flask-Migrate.
- flask db migrate -m "ScoDoc 9.0.4" # ajuster le message !
+ flask db migrate -m "ScoDoc 9.0.x: ..." # ajuster le message !
flask db upgrade
Ne pas oublier de commiter les migrations (`git add migrations` ...).
@@ -142,7 +142,7 @@ Mémo pour développeurs: séquence re-création d'une base:
dropdb SCODOC_DEV
tools/create_database.sh SCODOC_DEV # créé base SQL
flask db upgrade # créé les tables à partir des migrations
- flask sco-db-init # ajoute au besoin les constantes (todo: mettre en migration 0)
+ flask sco-db-init # ajoute au besoin les constantes (fait en migration 0)
# puis imports:
flask import-scodoc7-users
diff --git a/app/models/etudiants.py b/app/models/etudiants.py
index cf37a77f4..57eadbc78 100644
--- a/app/models/etudiants.py
+++ b/app/models/etudiants.py
@@ -138,6 +138,7 @@ class ItemSuivi(db.Model):
class ItemSuiviTag(db.Model):
__tablename__ = "itemsuivi_tags"
id = db.Column(db.Integer, primary_key=True)
+ dept_id = db.Column(db.Integer, db.ForeignKey("departement.id"), index=True)
tag_id = db.synonym("id")
title = db.Column(db.Text(), nullable=False, unique=True)
diff --git a/app/scodoc/sco_debouche.py b/app/scodoc/sco_debouche.py
index 8def02496..0a301ebf9 100644
--- a/app/scodoc/sco_debouche.py
+++ b/app/scodoc/sco_debouche.py
@@ -335,8 +335,11 @@ def itemsuivi_tag_search(term, REQUEST=None):
data = []
else:
r = ndb.SimpleDictFetch(
- "SELECT title FROM itemsuivi_tags WHERE title LIKE %(term)s",
- {"term": term + "%"},
+ "SELECT title FROM itemsuivi_tags WHERE title LIKE %(term)s AND dept_id=%(dept_id)s",
+ {
+ "term": term + "%",
+ "dept_id": g.scodoc_dept_id,
+ },
)
data = [x["title"] for x in r]
diff --git a/app/scodoc/sco_tag_module.py b/app/scodoc/sco_tag_module.py
index 246c95933..d8a78478f 100644
--- a/app/scodoc/sco_tag_module.py
+++ b/app/scodoc/sco_tag_module.py
@@ -86,7 +86,10 @@ class ScoTag(object):
# log("creating new tag: %s" % self.title)
cnx = ndb.GetDBConnexion()
self.tag_id = ndb.DBInsertDict(
- cnx, self.tag_table, {"title": self.title}, commit=True
+ cnx,
+ self.tag_table,
+ {"title": self.title, "dept_id": g.scodoc_dept_id},
+ commit=True,
)
if object_id:
self.tag_object(object_id)
@@ -203,8 +206,11 @@ def module_tag_search(term, REQUEST=None):
data = []
else:
r = ndb.SimpleDictFetch(
- "SELECT title FROM notes_tags WHERE title LIKE %(term)s",
- {"term": term + "%"},
+ "SELECT title FROM notes_tags WHERE title LIKE %(term)s AND dept_id=%(dept_id)s",
+ {
+ "term": term + "%",
+ "dept_id": g.scodoc_dept_id,
+ },
)
data = [x["title"] for x in r]
diff --git a/migrations/versions/d3d92b2d0092_scodoc_9_0_5_ajout_dept_id_sur_.py b/migrations/versions/d3d92b2d0092_scodoc_9_0_5_ajout_dept_id_sur_.py
new file mode 100644
index 000000000..8ab88cac7
--- /dev/null
+++ b/migrations/versions/d3d92b2d0092_scodoc_9_0_5_ajout_dept_id_sur_.py
@@ -0,0 +1,32 @@
+"""ScoDoc 9.0.5: ajout dept_id sur ItemSuiviTag
+
+Revision ID: d3d92b2d0092
+Revises: 017e32eb4773
+Create Date: 2021-08-29 20:57:55.564519
+
+"""
+from alembic import op
+import sqlalchemy as sa
+
+
+# revision identifiers, used by Alembic.
+revision = 'd3d92b2d0092'
+down_revision = '017e32eb4773'
+branch_labels = None
+depends_on = None
+
+
+def upgrade():
+ # ### commands auto generated by Alembic - please adjust! ###
+ op.add_column('itemsuivi_tags', sa.Column('dept_id', sa.Integer(), nullable=True))
+ op.create_index(op.f('ix_itemsuivi_tags_dept_id'), 'itemsuivi_tags', ['dept_id'], unique=False)
+ op.create_foreign_key(None, 'itemsuivi_tags', 'departement', ['dept_id'], ['id'])
+ # ### end Alembic commands ###
+
+
+def downgrade():
+ # ### commands auto generated by Alembic - please adjust! ###
+ op.drop_constraint(None, 'itemsuivi_tags', type_='foreignkey')
+ op.drop_index(op.f('ix_itemsuivi_tags_dept_id'), table_name='itemsuivi_tags')
+ op.drop_column('itemsuivi_tags', 'dept_id')
+ # ### end Alembic commands ###
diff --git a/sco_version.py b/sco_version.py
index 7c879eca5..2ac0ac77f 100644
--- a/sco_version.py
+++ b/sco_version.py
@@ -1,7 +1,7 @@
# -*- mode: python -*-
# -*- coding: utf-8 -*-
-SCOVERSION = "9.0.4"
+SCOVERSION = "9.0.5"
SCONAME = "ScoDoc"
--
GitLab