forked from ScoDoc/ScoDoc
Sépare les tags (modules et itemsuivi) par département
This commit is contained in:
parent
aee02d911e
commit
22475b1033
@ -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.
|
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
|
flask db upgrade
|
||||||
|
|
||||||
Ne pas oublier de commiter les migrations (`git add migrations` ...).
|
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
|
dropdb SCODOC_DEV
|
||||||
tools/create_database.sh SCODOC_DEV # créé base SQL
|
tools/create_database.sh SCODOC_DEV # créé base SQL
|
||||||
flask db upgrade # créé les tables à partir des migrations
|
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:
|
# puis imports:
|
||||||
flask import-scodoc7-users
|
flask import-scodoc7-users
|
||||||
|
@ -138,6 +138,7 @@ class ItemSuivi(db.Model):
|
|||||||
class ItemSuiviTag(db.Model):
|
class ItemSuiviTag(db.Model):
|
||||||
__tablename__ = "itemsuivi_tags"
|
__tablename__ = "itemsuivi_tags"
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
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")
|
tag_id = db.synonym("id")
|
||||||
title = db.Column(db.Text(), nullable=False, unique=True)
|
title = db.Column(db.Text(), nullable=False, unique=True)
|
||||||
|
|
||||||
|
@ -335,8 +335,11 @@ def itemsuivi_tag_search(term, REQUEST=None):
|
|||||||
data = []
|
data = []
|
||||||
else:
|
else:
|
||||||
r = ndb.SimpleDictFetch(
|
r = ndb.SimpleDictFetch(
|
||||||
"SELECT title FROM itemsuivi_tags WHERE title LIKE %(term)s",
|
"SELECT title FROM itemsuivi_tags WHERE title LIKE %(term)s AND dept_id=%(dept_id)s",
|
||||||
{"term": term + "%"},
|
{
|
||||||
|
"term": term + "%",
|
||||||
|
"dept_id": g.scodoc_dept_id,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
data = [x["title"] for x in r]
|
data = [x["title"] for x in r]
|
||||||
|
|
||||||
|
@ -86,7 +86,10 @@ class ScoTag(object):
|
|||||||
# log("creating new tag: %s" % self.title)
|
# log("creating new tag: %s" % self.title)
|
||||||
cnx = ndb.GetDBConnexion()
|
cnx = ndb.GetDBConnexion()
|
||||||
self.tag_id = ndb.DBInsertDict(
|
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:
|
if object_id:
|
||||||
self.tag_object(object_id)
|
self.tag_object(object_id)
|
||||||
@ -203,8 +206,11 @@ def module_tag_search(term, REQUEST=None):
|
|||||||
data = []
|
data = []
|
||||||
else:
|
else:
|
||||||
r = ndb.SimpleDictFetch(
|
r = ndb.SimpleDictFetch(
|
||||||
"SELECT title FROM notes_tags WHERE title LIKE %(term)s",
|
"SELECT title FROM notes_tags WHERE title LIKE %(term)s AND dept_id=%(dept_id)s",
|
||||||
{"term": term + "%"},
|
{
|
||||||
|
"term": term + "%",
|
||||||
|
"dept_id": g.scodoc_dept_id,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
data = [x["title"] for x in r]
|
data = [x["title"] for x in r]
|
||||||
|
|
||||||
|
@ -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 ###
|
@ -1,7 +1,7 @@
|
|||||||
# -*- mode: python -*-
|
# -*- mode: python -*-
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
SCOVERSION = "9.0.4"
|
SCOVERSION = "9.0.5"
|
||||||
|
|
||||||
SCONAME = "ScoDoc"
|
SCONAME = "ScoDoc"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user