Sépare les tags (modules et itemsuivi) par département

This commit is contained in:
Emmanuel Viennet 2021-08-29 21:21:41 +02:00
parent aee02d911e
commit 22475b1033
6 changed files with 50 additions and 8 deletions

View File

@ -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

View File

@ -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)

View File

@ -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]

View File

@ -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]

View File

@ -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 ###

View File

@ -1,7 +1,7 @@
# -*- mode: python -*-
# -*- coding: utf-8 -*-
SCOVERSION = "9.0.4"
SCOVERSION = "9.0.5"
SCONAME = "ScoDoc"