Skip to content
Snippets Groups Projects
Commit 22475b10 authored by Emmanuel Viennet's avatar Emmanuel Viennet
Browse files

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

parent aee02d91
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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)
......
......@@ -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]
......
......@@ -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]
......
"""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 ###
# -*- mode: python -*-
# -*- coding: utf-8 -*-
SCOVERSION = "9.0.4"
SCOVERSION = "9.0.5"
SCONAME = "ScoDoc"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment