From 3d4b903acf56ef248a635e42887d353c4981a7a3 Mon Sep 17 00:00:00 2001 From: Arthur ZHU Date: Thu, 30 Dec 2021 19:37:46 +0100 Subject: [PATCH] =?UTF-8?q?ajout=20error=20+=20offre=20obsol=C3=A8te?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/entreprises/models.py | 18 ++++++++++++ app/entreprises/routes.py | 10 ++++++- ...e_creation_table_relations_entreprrises.py | 28 +++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/app/entreprises/models.py b/app/entreprises/models.py index 10ae990e..e743df3d 100644 --- a/app/entreprises/models.py +++ b/app/entreprises/models.py @@ -88,6 +88,15 @@ class EntrepriseOffre(db.Model): missions = db.Column(db.Text) duree = db.Column(db.Text) + def to_dict(self): + return { + "intitule": self.intitule, + "description": self.description, + "type_offre": self.type_offre, + "missions": self.missions, + "duree": self.duree, + } + class EntrepriseLog(db.Model): __tablename__ = "entreprise_log" @@ -117,3 +126,12 @@ class EntrepriseEnvoiOffre(db.Model): receiver_id = db.Column(db.Integer, db.ForeignKey("user.id")) offre_id = db.Column(db.Integer, db.ForeignKey("entreprise_offre.id")) date_envoi = db.Column(db.DateTime(timezone=True), server_default=db.func.now()) + + +class EntrepriseEnvoiOffreEtudiant(db.Model): + __tablename__ = "entreprise_envoi_offre_etudiant" + id = db.Column(db.Integer, primary_key=True) + sender_id = db.Column(db.Integer, db.ForeignKey("user.id")) + receiver_id = db.Column(db.Integer, db.ForeignKey("identite.id")) + offre_id = db.Column(db.Integer, db.ForeignKey("entreprise_offre.id")) + date_envoi = db.Column(db.DateTime(timezone=True), server_default=db.func.now()) diff --git a/app/entreprises/routes.py b/app/entreprises/routes.py index 007af4cf..f99fa8ee 100644 --- a/app/entreprises/routes.py +++ b/app/entreprises/routes.py @@ -1,6 +1,6 @@ import os from config import Config -from datetime import datetime +from datetime import datetime, timedelta import glob import shutil @@ -123,6 +123,10 @@ def fiche_entreprise(id): offres = entreprise.offres offres_with_files = [] for offre in offres: + if datetime.now() - offre.date_ajout.replace(tzinfo=None) >= timedelta( + days=90 + ): # pour une date d'expiration ? + break files = [] path = os.path.join( Config.SCODOC_VAR_DIR, @@ -626,6 +630,8 @@ def json_etudiants(): Retourne: le JSON de tous les étudiants (nom, prenom, formation actuelle?) correspondant au terme """ + if request.args.get("term") == None: + abort(400) term = request.args.get("term").strip() etudiants = Identite.query.filter(Identite.nom.ilike(f"%{term}%")).all() list = [] @@ -657,6 +663,8 @@ def json_responsables(): Retourne: le JSON de tous les utilisateurs (nom, prenom, login) correspondant au terme """ + if request.args.get("term") == None: + abort(400) term = request.args.get("term").strip() responsables = User.query.filter( User.nom.ilike(f"%{term}%"), User.nom.is_not(None), User.prenom.is_not(None) diff --git a/migrations/versions/2dfafee725ae_creation_table_relations_entreprrises.py b/migrations/versions/2dfafee725ae_creation_table_relations_entreprrises.py index 05adc356..e47a9879 100644 --- a/migrations/versions/2dfafee725ae_creation_table_relations_entreprrises.py +++ b/migrations/versions/2dfafee725ae_creation_table_relations_entreprrises.py @@ -97,6 +97,33 @@ def upgrade(): sa.PrimaryKeyConstraint("id"), ) + op.create_table( + "entreprise_envoi_offre_etudiant", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("sender_id", sa.Integer(), nullable=True), + sa.Column("receiver_id", sa.Integer(), nullable=True), + sa.Column("offre_id", sa.Integer(), nullable=True), + sa.Column( + "date_envoi", + sa.DateTime(timezone=True), + server_default=sa.text("now()"), + nullable=True, + ), + sa.ForeignKeyConstraint( + ["offre_id"], + ["entreprise_offre.id"], + ), + sa.ForeignKeyConstraint( + ["sender_id"], + ["user.id"], + ), + sa.ForeignKeyConstraint( + ["receiver_id"], + ["identite.id"], + ), + sa.PrimaryKeyConstraint("id"), + ) + op.drop_constraint( "entreprise_contact_entreprise_corresp_id_fkey", "entreprise_contact", @@ -249,6 +276,7 @@ def downgrade(): op.drop_column("entreprise_contact", "nom") op.drop_table("entreprise_envoi_offre") + op.drop_table("entreprise_envoi_offre_etudiant") op.drop_table("entreprise_offre") op.drop_table("entreprise_etudiant") op.drop_table("entreprise_log")