From 6d1744dacd9a219acec2fc87a44604c224cc8022 Mon Sep 17 00:00:00 2001 From: Arthur ZHU Date: Mon, 24 Jan 2022 18:07:54 +0100 Subject: [PATCH] offres date expiration --- app/entreprises/forms.py | 6 + app/entreprises/models.py | 1 + app/entreprises/routes.py | 9 +- ...ables_application_relations_entreprises.py | 253 ++++++++++++++++++ ...ables_application_relations_entreprises.py | 165 ------------ 5 files changed, 265 insertions(+), 169 deletions(-) create mode 100644 migrations/versions/bd5e795fe77d_tables_application_relations_entreprises.py delete mode 100644 migrations/versions/ee3f2eab6f08_tables_application_relations_entreprises.py diff --git a/app/entreprises/forms.py b/app/entreprises/forms.py index 1f76732d..9ea92781 100644 --- a/app/entreprises/forms.py +++ b/app/entreprises/forms.py @@ -138,6 +138,9 @@ class OffreCreationForm(FlaskForm): "Missions", validators=[DataRequired(message=CHAMP_REQUIS)] ) duree = StringField("Durée", validators=[DataRequired(message=CHAMP_REQUIS)]) + expiration_date = DateField( + "Date expiration", validators=[DataRequired(message=CHAMP_REQUIS)] + ) submit = SubmitField("Envoyer", render_kw={"style": "margin-bottom: 10px;"}) @@ -155,6 +158,9 @@ class OffreModificationForm(FlaskForm): "Missions", validators=[DataRequired(message=CHAMP_REQUIS)] ) duree = StringField("Durée", validators=[DataRequired(message=CHAMP_REQUIS)]) + expiration_date = DateField( + "Date expiration", validators=[DataRequired(message=CHAMP_REQUIS)] + ) submit = SubmitField("Modifier", render_kw={"style": "margin-bottom: 10px;"}) diff --git a/app/entreprises/models.py b/app/entreprises/models.py index 865d8ff2..0585b4cc 100644 --- a/app/entreprises/models.py +++ b/app/entreprises/models.py @@ -87,6 +87,7 @@ class EntrepriseOffre(db.Model): type_offre = db.Column(db.Text) missions = db.Column(db.Text) duree = db.Column(db.Text) + expiration_date = db.Column(db.Date) def to_dict(self): return { diff --git a/app/entreprises/routes.py b/app/entreprises/routes.py index f99fa8ee..7618d164 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, timedelta +from datetime import datetime, date import glob import shutil @@ -123,9 +123,7 @@ 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 ? + if date.today() > offre.expiration_date: break files = [] path = os.path.join( @@ -350,6 +348,7 @@ def add_offre(id): type_offre=form.type_offre.data.strip(), missions=form.missions.data.strip(), duree=form.duree.data.strip(), + expiration_date=form.expiration_date.data, ) log = EntrepriseLog( authenticated_user=current_user.user_name, @@ -381,6 +380,7 @@ def edit_offre(id): offre.type_offre = form.type_offre.data.strip() offre.missions = form.missions.data.strip() offre.duree = form.duree.data.strip() + offre.expiration_date = form.expiration_date.data log = EntrepriseLog( authenticated_user=current_user.user_name, object=offre.entreprise_id, @@ -396,6 +396,7 @@ def edit_offre(id): form.type_offre.data = offre.type_offre form.missions.data = offre.missions form.duree.data = offre.duree + form.expiration_date.data = offre.expiration_date return render_template( "entreprises/form.html", title=("Modification offre"), form=form ) diff --git a/migrations/versions/bd5e795fe77d_tables_application_relations_entreprises.py b/migrations/versions/bd5e795fe77d_tables_application_relations_entreprises.py new file mode 100644 index 00000000..54ea8e09 --- /dev/null +++ b/migrations/versions/bd5e795fe77d_tables_application_relations_entreprises.py @@ -0,0 +1,253 @@ +"""tables application relations entreprises + +Revision ID: bd5e795fe77d +Revises: f40fbaf5831c +Create Date: 2022-01-24 17:43:29.261983 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision = "bd5e795fe77d" +down_revision = "f40fbaf5831c" +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table( + "are_entreprise_log", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column( + "date", + sa.DateTime(timezone=True), + server_default=sa.text("now()"), + nullable=True, + ), + sa.Column("authenticated_user", sa.Text(), nullable=True), + sa.Column("object", sa.Integer(), nullable=True), + sa.Column("text", sa.Text(), nullable=True), + sa.PrimaryKeyConstraint("id"), + ) + op.create_table( + "are_entreprises", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("siret", sa.Text(), nullable=True), + sa.Column("nom", sa.Text(), nullable=True), + sa.Column("adresse", sa.Text(), nullable=True), + sa.Column("codepostal", sa.Text(), nullable=True), + sa.Column("ville", sa.Text(), nullable=True), + sa.Column("pays", sa.Text(), nullable=True), + sa.PrimaryKeyConstraint("id"), + ) + op.create_table( + "are_entreprise_contact", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("entreprise_id", sa.Integer(), nullable=True), + sa.Column("nom", sa.Text(), nullable=True), + sa.Column("prenom", sa.Text(), nullable=True), + sa.Column("telephone", sa.Text(), nullable=True), + sa.Column("mail", sa.Text(), nullable=True), + sa.Column("poste", sa.Text(), nullable=True), + sa.Column("service", sa.Text(), nullable=True), + sa.ForeignKeyConstraint( + ["entreprise_id"], ["are_entreprises.id"], ondelete="cascade" + ), + sa.PrimaryKeyConstraint("id"), + ) + op.create_table( + "are_entreprise_etudiant", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("entreprise_id", sa.Integer(), nullable=True), + sa.Column("etudid", sa.Integer(), nullable=True), + sa.Column("type_offre", sa.Text(), nullable=True), + sa.Column("date_debut", sa.Date(), nullable=True), + sa.Column("date_fin", sa.Date(), nullable=True), + sa.Column("formation_text", sa.Text(), nullable=True), + sa.Column("formation_scodoc", sa.Integer(), nullable=True), + sa.ForeignKeyConstraint( + ["entreprise_id"], + ["are_entreprises.id"], + ), + sa.PrimaryKeyConstraint("id"), + ) + op.create_table( + "are_entreprise_offre", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("entreprise_id", sa.Integer(), nullable=True), + sa.Column( + "date_ajout", + sa.DateTime(timezone=True), + server_default=sa.text("now()"), + nullable=True, + ), + sa.Column("intitule", sa.Text(), nullable=True), + sa.Column("description", sa.Text(), nullable=True), + sa.Column("type_offre", sa.Text(), nullable=True), + sa.Column("missions", sa.Text(), nullable=True), + sa.Column("duree", sa.Text(), nullable=True), + sa.Column("expiration_date", sa.Date(), nullable=True), + sa.ForeignKeyConstraint( + ["entreprise_id"], ["are_entreprises.id"], ondelete="cascade" + ), + sa.PrimaryKeyConstraint("id"), + ) + op.create_table( + "are_entreprise_envoi_offre", + 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"], + ["are_entreprise_offre.id"], + ), + sa.ForeignKeyConstraint( + ["receiver_id"], + ["user.id"], + ), + sa.ForeignKeyConstraint( + ["sender_id"], + ["user.id"], + ), + sa.PrimaryKeyConstraint("id"), + ) + op.create_table( + "are_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"], + ["are_entreprise_offre.id"], + ), + sa.ForeignKeyConstraint( + ["receiver_id"], + ["identite.id"], + ), + sa.ForeignKeyConstraint( + ["sender_id"], + ["user.id"], + ), + sa.PrimaryKeyConstraint("id"), + ) + op.drop_table("entreprise_contact") + op.drop_table("entreprise_correspondant") + op.drop_index("ix_entreprises_dept_id", table_name="entreprises") + op.drop_table("entreprises") + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table( + "entreprises", + sa.Column( + "id", + sa.INTEGER(), + server_default=sa.text("nextval('entreprises_id_seq'::regclass)"), + autoincrement=True, + nullable=False, + ), + sa.Column("nom", sa.TEXT(), autoincrement=False, nullable=True), + sa.Column("adresse", sa.TEXT(), autoincrement=False, nullable=True), + sa.Column("ville", sa.TEXT(), autoincrement=False, nullable=True), + sa.Column("codepostal", sa.TEXT(), autoincrement=False, nullable=True), + sa.Column("pays", sa.TEXT(), autoincrement=False, nullable=True), + sa.Column("localisation", sa.TEXT(), autoincrement=False, nullable=True), + sa.Column("dept_id", sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column( + "date_creation", + postgresql.TIMESTAMP(timezone=True), + server_default=sa.text("now()"), + autoincrement=False, + nullable=True, + ), + sa.Column("secteur", sa.TEXT(), autoincrement=False, nullable=True), + sa.Column("privee", sa.TEXT(), autoincrement=False, nullable=True), + sa.Column("plus10salaries", sa.BOOLEAN(), autoincrement=False, nullable=True), + sa.Column("contact_origine", sa.TEXT(), autoincrement=False, nullable=True), + sa.Column("note", sa.TEXT(), autoincrement=False, nullable=True), + sa.Column("qualite_relation", sa.INTEGER(), autoincrement=False, nullable=True), + sa.ForeignKeyConstraint( + ["dept_id"], ["departement.id"], name="entreprises_dept_id_fkey" + ), + sa.PrimaryKeyConstraint("id", name="entreprises_pkey"), + postgresql_ignore_search_path=False, + ) + op.create_index("ix_entreprises_dept_id", "entreprises", ["dept_id"], unique=False) + op.create_table( + "entreprise_contact", + sa.Column("id", sa.INTEGER(), autoincrement=True, nullable=False), + sa.Column("entreprise_id", sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column( + "entreprise_corresp_id", sa.INTEGER(), autoincrement=False, nullable=True + ), + sa.Column("etudid", sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column("type_contact", sa.TEXT(), autoincrement=False, nullable=True), + sa.Column( + "date", + postgresql.TIMESTAMP(timezone=True), + autoincrement=False, + nullable=True, + ), + sa.Column("enseignant", sa.TEXT(), autoincrement=False, nullable=True), + sa.Column("description", sa.TEXT(), autoincrement=False, nullable=True), + sa.ForeignKeyConstraint( + ["entreprise_corresp_id"], + ["entreprise_correspondant.id"], + name="entreprise_contact_entreprise_corresp_id_fkey", + ), + sa.ForeignKeyConstraint( + ["entreprise_id"], + ["entreprises.id"], + name="entreprise_contact_entreprise_id_fkey", + ), + sa.PrimaryKeyConstraint("id", name="entreprise_contact_pkey"), + ) + op.create_table( + "entreprise_correspondant", + sa.Column("id", sa.INTEGER(), autoincrement=True, nullable=False), + sa.Column("entreprise_id", sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column("nom", sa.TEXT(), autoincrement=False, nullable=True), + sa.Column("prenom", sa.TEXT(), autoincrement=False, nullable=True), + sa.Column("civilite", sa.TEXT(), autoincrement=False, nullable=True), + sa.Column("fonction", sa.TEXT(), autoincrement=False, nullable=True), + sa.Column("phone1", sa.TEXT(), autoincrement=False, nullable=True), + sa.Column("phone2", sa.TEXT(), autoincrement=False, nullable=True), + sa.Column("mobile", sa.TEXT(), autoincrement=False, nullable=True), + sa.Column("mail1", sa.TEXT(), autoincrement=False, nullable=True), + sa.Column("mail2", sa.TEXT(), autoincrement=False, nullable=True), + sa.Column("fax", sa.TEXT(), autoincrement=False, nullable=True), + sa.Column("note", sa.TEXT(), autoincrement=False, nullable=True), + sa.ForeignKeyConstraint( + ["entreprise_id"], + ["entreprises.id"], + name="entreprise_correspondant_entreprise_id_fkey", + ), + sa.PrimaryKeyConstraint("id", name="entreprise_correspondant_pkey"), + ) + op.drop_table("are_entreprise_envoi_offre_etudiant") + op.drop_table("are_entreprise_envoi_offre") + op.drop_table("are_entreprise_offre") + op.drop_table("are_entreprise_etudiant") + op.drop_table("are_entreprise_contact") + op.drop_table("are_entreprises") + op.drop_table("are_entreprise_log") + # ### end Alembic commands ### diff --git a/migrations/versions/ee3f2eab6f08_tables_application_relations_entreprises.py b/migrations/versions/ee3f2eab6f08_tables_application_relations_entreprises.py deleted file mode 100644 index 08d5200f..00000000 --- a/migrations/versions/ee3f2eab6f08_tables_application_relations_entreprises.py +++ /dev/null @@ -1,165 +0,0 @@ -"""tables application relations entreprises - -Revision ID: ee3f2eab6f08 -Revises: f40fbaf5831c -Create Date: 2022-01-24 10:44:09.706261 - -""" -from alembic import op -import sqlalchemy as sa -from sqlalchemy.dialects import postgresql - -# revision identifiers, used by Alembic. -revision = 'ee3f2eab6f08' -down_revision = 'f40fbaf5831c' -branch_labels = None -depends_on = None - - -def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.create_table('are_entreprise_log', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('date', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True), - sa.Column('authenticated_user', sa.Text(), nullable=True), - sa.Column('object', sa.Integer(), nullable=True), - sa.Column('text', sa.Text(), nullable=True), - sa.PrimaryKeyConstraint('id') - ) - op.create_table('are_entreprises', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('siret', sa.Text(), nullable=True), - sa.Column('nom', sa.Text(), nullable=True), - sa.Column('adresse', sa.Text(), nullable=True), - sa.Column('codepostal', sa.Text(), nullable=True), - sa.Column('ville', sa.Text(), nullable=True), - sa.Column('pays', sa.Text(), nullable=True), - sa.PrimaryKeyConstraint('id') - ) - op.create_table('are_entreprise_contact', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('entreprise_id', sa.Integer(), nullable=True), - sa.Column('nom', sa.Text(), nullable=True), - sa.Column('prenom', sa.Text(), nullable=True), - sa.Column('telephone', sa.Text(), nullable=True), - sa.Column('mail', sa.Text(), nullable=True), - sa.Column('poste', sa.Text(), nullable=True), - sa.Column('service', sa.Text(), nullable=True), - sa.ForeignKeyConstraint(['entreprise_id'], ['are_entreprises.id'], ondelete='cascade'), - sa.PrimaryKeyConstraint('id') - ) - op.create_table('are_entreprise_etudiant', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('entreprise_id', sa.Integer(), nullable=True), - sa.Column('etudid', sa.Integer(), nullable=True), - sa.Column('type_offre', sa.Text(), nullable=True), - sa.Column('date_debut', sa.Date(), nullable=True), - sa.Column('date_fin', sa.Date(), nullable=True), - sa.Column('formation_text', sa.Text(), nullable=True), - sa.Column('formation_scodoc', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['entreprise_id'], ['are_entreprises.id'], ), - sa.PrimaryKeyConstraint('id') - ) - op.create_table('are_entreprise_offre', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('entreprise_id', sa.Integer(), nullable=True), - sa.Column('date_ajout', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True), - sa.Column('intitule', sa.Text(), nullable=True), - sa.Column('description', sa.Text(), nullable=True), - sa.Column('type_offre', sa.Text(), nullable=True), - sa.Column('missions', sa.Text(), nullable=True), - sa.Column('duree', sa.Text(), nullable=True), - sa.ForeignKeyConstraint(['entreprise_id'], ['are_entreprises.id'], ondelete='cascade'), - sa.PrimaryKeyConstraint('id') - ) - op.create_table('are_entreprise_envoi_offre', - 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'], ['are_entreprise_offre.id'], ), - sa.ForeignKeyConstraint(['receiver_id'], ['user.id'], ), - sa.ForeignKeyConstraint(['sender_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('id') - ) - op.create_table('are_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'], ['are_entreprise_offre.id'], ), - sa.ForeignKeyConstraint(['receiver_id'], ['identite.id'], ), - sa.ForeignKeyConstraint(['sender_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('id') - ) - op.drop_table('entreprise_contact') - op.drop_table('entreprise_correspondant') - op.drop_index('ix_entreprises_dept_id', table_name='entreprises') - op.drop_table('entreprises') - # ### end Alembic commands ### - - -def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.create_table('entreprises', - sa.Column('id', sa.INTEGER(), server_default=sa.text("nextval('entreprises_id_seq'::regclass)"), autoincrement=True, nullable=False), - sa.Column('nom', sa.TEXT(), autoincrement=False, nullable=True), - sa.Column('adresse', sa.TEXT(), autoincrement=False, nullable=True), - sa.Column('ville', sa.TEXT(), autoincrement=False, nullable=True), - sa.Column('codepostal', sa.TEXT(), autoincrement=False, nullable=True), - sa.Column('pays', sa.TEXT(), autoincrement=False, nullable=True), - sa.Column('localisation', sa.TEXT(), autoincrement=False, nullable=True), - sa.Column('dept_id', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('date_creation', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=True), - sa.Column('secteur', sa.TEXT(), autoincrement=False, nullable=True), - sa.Column('privee', sa.TEXT(), autoincrement=False, nullable=True), - sa.Column('plus10salaries', sa.BOOLEAN(), autoincrement=False, nullable=True), - sa.Column('contact_origine', sa.TEXT(), autoincrement=False, nullable=True), - sa.Column('note', sa.TEXT(), autoincrement=False, nullable=True), - sa.Column('qualite_relation', sa.INTEGER(), autoincrement=False, nullable=True), - sa.ForeignKeyConstraint(['dept_id'], ['departement.id'], name='entreprises_dept_id_fkey'), - sa.PrimaryKeyConstraint('id', name='entreprises_pkey'), - postgresql_ignore_search_path=False - ) - op.create_index('ix_entreprises_dept_id', 'entreprises', ['dept_id'], unique=False) - op.create_table('entreprise_correspondant', - sa.Column('id', sa.INTEGER(), server_default=sa.text("nextval('entreprise_correspondant_id_seq'::regclass)"), autoincrement=True, nullable=False), - sa.Column('entreprise_id', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('nom', sa.TEXT(), autoincrement=False, nullable=True), - sa.Column('prenom', sa.TEXT(), autoincrement=False, nullable=True), - sa.Column('civilite', sa.TEXT(), autoincrement=False, nullable=True), - sa.Column('fonction', sa.TEXT(), autoincrement=False, nullable=True), - sa.Column('phone1', sa.TEXT(), autoincrement=False, nullable=True), - sa.Column('phone2', sa.TEXT(), autoincrement=False, nullable=True), - sa.Column('mobile', sa.TEXT(), autoincrement=False, nullable=True), - sa.Column('mail1', sa.TEXT(), autoincrement=False, nullable=True), - sa.Column('mail2', sa.TEXT(), autoincrement=False, nullable=True), - sa.Column('fax', sa.TEXT(), autoincrement=False, nullable=True), - sa.Column('note', sa.TEXT(), autoincrement=False, nullable=True), - sa.ForeignKeyConstraint(['entreprise_id'], ['entreprises.id'], name='entreprise_correspondant_entreprise_id_fkey'), - sa.PrimaryKeyConstraint('id', name='entreprise_correspondant_pkey'), - postgresql_ignore_search_path=False - ) - op.create_table('entreprise_contact', - sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column('entreprise_id', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('entreprise_corresp_id', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('etudid', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('type_contact', sa.TEXT(), autoincrement=False, nullable=True), - sa.Column('date', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=True), - sa.Column('enseignant', sa.TEXT(), autoincrement=False, nullable=True), - sa.Column('description', sa.TEXT(), autoincrement=False, nullable=True), - sa.ForeignKeyConstraint(['entreprise_corresp_id'], ['entreprise_correspondant.id'], name='entreprise_contact_entreprise_corresp_id_fkey'), - sa.ForeignKeyConstraint(['entreprise_id'], ['entreprises.id'], name='entreprise_contact_entreprise_id_fkey'), - sa.PrimaryKeyConstraint('id', name='entreprise_contact_pkey') - ) - op.drop_table('are_entreprise_envoi_offre_etudiant') - op.drop_table('are_entreprise_envoi_offre') - op.drop_table('are_entreprise_offre') - op.drop_table('are_entreprise_etudiant') - op.drop_table('are_entreprise_contact') - op.drop_table('are_entreprises') - op.drop_table('are_entreprise_log') - # ### end Alembic commands ###