From 126f719f7aa1567b56082c4f3ea96910877227ae Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Mon, 10 Jan 2022 15:15:26 +0100 Subject: [PATCH] Index INE et NIP --- app/models/etudiants.py | 4 +-- app/views/notes.py | 15 ++++++-- .../versions/f40fbaf5831c_index_ine_et_nip.py | 34 +++++++++++++++++++ 3 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 migrations/versions/f40fbaf5831c_index_ine_et_nip.py diff --git a/app/models/etudiants.py b/app/models/etudiants.py index 9c8457fac..ba0fafcad 100644 --- a/app/models/etudiants.py +++ b/app/models/etudiants.py @@ -38,8 +38,8 @@ class Identite(db.Model): boursier = db.Column(db.Boolean()) # True si boursier ('O' en ScoDoc7) photo_filename = db.Column(db.Text()) # Codes INE et NIP pas unique car le meme etud peut etre ds plusieurs dept - code_nip = db.Column(db.Text()) - code_ine = db.Column(db.Text()) + code_nip = db.Column(db.Text(), index=True) + code_ine = db.Column(db.Text(), index=True) # Ancien id ScoDoc7 pour les migrations de bases anciennes # ne pas utiliser après migrate_scodoc7_dept_archives scodoc7_id = db.Column(db.Text(), nullable=True) diff --git a/app/views/notes.py b/app/views/notes.py index c9fec1a1c..35c9ca837 100644 --- a/app/views/notes.py +++ b/app/views/notes.py @@ -279,6 +279,7 @@ def formsemestre_bulletinetud( force_publishing=False, prefer_mail_perso=False, code_nip=None, + code_ine=None, ): if not formsemestre_id: flask.abort(404, "argument manquant: formsemestre_id") @@ -292,6 +293,14 @@ def formsemestre_bulletinetud( etud = models.Identite.query.filter_by( code_nip=str(code_nip) ).first_or_404() + elif code_ine: + etud = models.Identite.query.filter_by( + code_ine=str(code_ine) + ).first_or_404() + else: + raise ScoValueError( + "Paramètre manquant: spécifier code_nip ou etudid ou code_ine" + ) if format == "json": r = bulletin_but.ResultatsSemestreBUT(formsemestre) return jsonify(r.bulletin_etud(etud, formsemestre)) @@ -309,8 +318,10 @@ def formsemestre_bulletinetud( sco=ScoData(), ) - if not (etudid or code_nip): - raise ScoValueError("Paramètre manquant: spécifier code_nip ou etudid") + if not (etudid or code_nip or code_ine): + raise ScoValueError( + "Paramètre manquant: spécifier code_nip ou etudid ou code_ine" + ) if format == "oldjson": format = "json" return sco_bulletins.formsemestre_bulletinetud( diff --git a/migrations/versions/f40fbaf5831c_index_ine_et_nip.py b/migrations/versions/f40fbaf5831c_index_ine_et_nip.py new file mode 100644 index 000000000..7ff0473d4 --- /dev/null +++ b/migrations/versions/f40fbaf5831c_index_ine_et_nip.py @@ -0,0 +1,34 @@ +"""index ine et nip + +Revision ID: f40fbaf5831c +Revises: 91be8a06d423 +Create Date: 2022-01-10 15:13:06.867903 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision = "f40fbaf5831c" +down_revision = "91be8a06d423" +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_index( + op.f("ix_identite_code_ine"), "identite", ["code_ine"], unique=False + ) + op.create_index( + op.f("ix_identite_code_nip"), "identite", ["code_nip"], unique=False + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index(op.f("ix_identite_code_nip"), table_name="identite") + op.drop_index(op.f("ix_identite_code_ine"), table_name="identite") + # ### end Alembic commands ###