From 626dc0157a5ebcad92d6bca3e68a7bbe5374930a Mon Sep 17 00:00:00 2001 From: Arthur ZHU Date: Tue, 1 Mar 2022 18:45:04 +0100 Subject: [PATCH] =?UTF-8?q?rendre=20expir=C3=A9e=20une=20offre?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/entreprises/forms.py | 8 +- app/entreprises/models.py | 29 +++---- app/entreprises/routes.py | 23 ++++- app/templates/entreprises/_offre.html | 8 +- ...b81be_tables_module_gestion_relations_.py} | 84 ++++++++----------- 5 files changed, 76 insertions(+), 76 deletions(-) rename migrations/versions/{717a8dfe2915_tables_module_gestion_relations_.py => af05f03b81be_tables_module_gestion_relations_.py} (87%) diff --git a/app/entreprises/forms.py b/app/entreprises/forms.py index bb76a3c4..0540c080 100644 --- a/app/entreprises/forms.py +++ b/app/entreprises/forms.py @@ -158,9 +158,7 @@ class OffreCreationForm(FlaskForm): ) duree = _build_string_field("Durée (*)") depts = MultiCheckboxField("Départements", validators=[Optional()], coerce=int) - expiration_date = DateField( - "Date expiration (*)", validators=[DataRequired(message=CHAMP_REQUIS)] - ) + expiration_date = DateField("Date expiration", validators=[Optional()]) submit = SubmitField("Envoyer", render_kw=SUBMIT_MARGE) def __init__(self, *args, **kwargs): @@ -186,9 +184,7 @@ class OffreModificationForm(FlaskForm): ) duree = _build_string_field("Durée (*)") depts = MultiCheckboxField("Départements", validators=[Optional()], coerce=int) - expiration_date = DateField( - "Date expiration (*)", validators=[DataRequired(message=CHAMP_REQUIS)] - ) + expiration_date = DateField("Date expiration", validators=[Optional()]) submit = SubmitField("Modifier", render_kw=SUBMIT_MARGE) def __init__(self, *args, **kwargs): diff --git a/app/entreprises/models.py b/app/entreprises/models.py index 923b2445..dd0b4ba4 100644 --- a/app/entreprises/models.py +++ b/app/entreprises/models.py @@ -9,7 +9,7 @@ class Entreprise(db.Model): adresse = db.Column(db.Text) codepostal = db.Column(db.Text) ville = db.Column(db.Text) - pays = db.Column(db.Text) + pays = db.Column(db.Text, default="FRANCE") visible = db.Column(db.Boolean, default=False) contacts = db.relationship( "EntrepriseContact", @@ -36,7 +36,7 @@ class Entreprise(db.Model): class EntrepriseContact(db.Model): - __tablename__ = "are_entreprise_contact" + __tablename__ = "are_contacts" id = db.Column(db.Integer, primary_key=True) entreprise_id = db.Column( db.Integer, db.ForeignKey("are_entreprises.id", ondelete="cascade") @@ -62,7 +62,7 @@ class EntrepriseContact(db.Model): class EntrepriseOffre(db.Model): - __tablename__ = "are_entreprise_offre" + __tablename__ = "are_offres" id = db.Column(db.Integer, primary_key=True) entreprise_id = db.Column( db.Integer, db.ForeignKey("are_entreprises.id", ondelete="cascade") @@ -74,6 +74,7 @@ class EntrepriseOffre(db.Model): missions = db.Column(db.Text) duree = db.Column(db.Text) expiration_date = db.Column(db.Date) + expired = db.Column(db.Boolean, default=False) def to_dict(self): return { @@ -86,7 +87,7 @@ class EntrepriseOffre(db.Model): class EntrepriseLog(db.Model): - __tablename__ = "are_entreprise_log" + __tablename__ = "are_logs" id = db.Column(db.Integer, primary_key=True) date = db.Column(db.DateTime(timezone=True), server_default=db.func.now()) authenticated_user = db.Column(db.Text) @@ -95,7 +96,7 @@ class EntrepriseLog(db.Model): class EntrepriseEtudiant(db.Model): - __tablename__ = "are_entreprise_etudiant" + __tablename__ = "are_etudiants" id = db.Column(db.Integer, primary_key=True) entreprise_id = db.Column( db.Integer, db.ForeignKey("are_entreprises.id", ondelete="cascade") @@ -109,35 +110,29 @@ class EntrepriseEtudiant(db.Model): class EntrepriseEnvoiOffre(db.Model): - __tablename__ = "are_entreprise_envoi_offre" + __tablename__ = "are_envoi_offre" id = db.Column(db.Integer, primary_key=True) sender_id = db.Column(db.Integer, db.ForeignKey("user.id", ondelete="cascade")) receiver_id = db.Column(db.Integer, db.ForeignKey("user.id", ondelete="cascade")) - offre_id = db.Column( - db.Integer, db.ForeignKey("are_entreprise_offre.id", ondelete="cascade") - ) + offre_id = db.Column(db.Integer, db.ForeignKey("are_offres.id", ondelete="cascade")) date_envoi = db.Column(db.DateTime(timezone=True), server_default=db.func.now()) class EntrepriseEnvoiOffreEtudiant(db.Model): - __tablename__ = "are_entreprise_envoi_offre_etudiant" + __tablename__ = "are_envoi_offre_etudiant" id = db.Column(db.Integer, primary_key=True) sender_id = db.Column(db.Integer, db.ForeignKey("user.id", ondelete="cascade")) receiver_id = db.Column( db.Integer, db.ForeignKey("identite.id", ondelete="cascade") ) - offre_id = db.Column( - db.Integer, db.ForeignKey("are_entreprise_offre.id", ondelete="cascade") - ) + offre_id = db.Column(db.Integer, db.ForeignKey("are_offres.id", ondelete="cascade")) date_envoi = db.Column(db.DateTime(timezone=True), server_default=db.func.now()) class EntrepriseOffreDepartement(db.Model): - __tablename__ = "are_entreprise_offre_departement" + __tablename__ = "are_offre_departement" id = db.Column(db.Integer, primary_key=True) - offre_id = db.Column( - db.Integer, db.ForeignKey("are_entreprise_offre.id", ondelete="cascade") - ) + offre_id = db.Column(db.Integer, db.ForeignKey("are_offres.id", ondelete="cascade")) dept_id = db.Column(db.Integer, db.ForeignKey("departement.id", ondelete="cascade")) diff --git a/app/entreprises/routes.py b/app/entreprises/routes.py index be7f629f..a72b2eb8 100644 --- a/app/entreprises/routes.py +++ b/app/entreprises/routes.py @@ -131,7 +131,13 @@ def fiche_entreprise(id): offres_with_files = [] depts = are.get_depts() for offre in entreprise.offres: - if date.today() < offre.expiration_date: + if not offre.expired and ( + offre.expiration_date is None + or ( + offre.expiration_date is not None + and date.today() < offre.expiration_date + ) + ): offre_with_files = are.get_offre_files_and_depts(offre, depts) if offre_with_files is not None: offres_with_files.append(offre_with_files) @@ -249,7 +255,9 @@ def offres_expirees(id): offres_expirees_with_files = [] depts = are.get_depts() for offre in entreprise.offres: - if date.today() > offre.expiration_date: + if offre.expired or ( + offre.expiration_date is not None and date.today() > offre.expiration_date + ): offre_expiree_with_files = are.get_offre_files_and_depts(offre, depts) if offre_expiree_with_files is not None: offres_expirees_with_files.append(offre_expiree_with_files) @@ -624,6 +632,17 @@ def delete_offre_recue(id): return redirect(url_for("entreprises.offres_recues")) +@bp.route("/expired/", methods=["GET", "POST"]) +@permission_required(Permission.RelationsEntreprisesChange) +def expired(id): + offre = EntrepriseOffre.query.filter_by(id=id).first_or_404( + description=f"offre {id} inconnue" + ) + offre.expired = not offre.expired + db.session.commit() + return redirect(url_for("entreprises.fiche_entreprise", id=offre.entreprise_id)) + + @bp.route("/add_contact/", methods=["GET", "POST"]) @permission_required(Permission.RelationsEntreprisesChange) def add_contact(id): diff --git a/app/templates/entreprises/_offre.html b/app/templates/entreprises/_offre.html index 0176ddd2..cff6f03a 100644 --- a/app/templates/entreprises/_offre.html +++ b/app/templates/entreprises/_offre.html @@ -29,6 +29,12 @@ {% if current_user.has_permission(current_user.Permission.RelationsEntreprisesSend, None) %} Envoyer l'offre {% endif %} + {% if current_user.has_permission(current_user.Permission.RelationsEntreprisesChange, None) %} + {% if not offre[0].expired %} + Rendre expirée + {% else %} + Rendre non expirée + {% endif %} + {% endif %} - \ No newline at end of file diff --git a/migrations/versions/717a8dfe2915_tables_module_gestion_relations_.py b/migrations/versions/af05f03b81be_tables_module_gestion_relations_.py similarity index 87% rename from migrations/versions/717a8dfe2915_tables_module_gestion_relations_.py rename to migrations/versions/af05f03b81be_tables_module_gestion_relations_.py index eb32d4c1..7f23ca9f 100644 --- a/migrations/versions/717a8dfe2915_tables_module_gestion_relations_.py +++ b/migrations/versions/af05f03b81be_tables_module_gestion_relations_.py @@ -1,8 +1,8 @@ """tables module gestion relations entreprises -Revision ID: 717a8dfe2915 +Revision ID: af05f03b81be Revises: b9aadc10227f -Create Date: 2022-02-22 20:18:57.171246 +Create Date: 2022-03-01 17:12:32.927643 """ from alembic import op @@ -10,7 +10,7 @@ import sqlalchemy as sa from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. -revision = "717a8dfe2915" +revision = "af05f03b81be" down_revision = "b9aadc10227f" branch_labels = None depends_on = None @@ -18,20 +18,6 @@ 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), @@ -44,6 +30,20 @@ def upgrade(): sa.Column("visible", sa.Boolean(), nullable=True), sa.PrimaryKeyConstraint("id"), ) + op.create_table( + "are_logs", + 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_preferences", sa.Column("id", sa.Integer(), nullable=False), @@ -52,7 +52,7 @@ def upgrade(): sa.PrimaryKeyConstraint("id"), ) op.create_table( - "are_entreprise_contact", + "are_contacts", sa.Column("id", sa.Integer(), nullable=False), sa.Column("entreprise_id", sa.Integer(), nullable=True), sa.Column("nom", sa.Text(), nullable=True), @@ -67,7 +67,7 @@ def upgrade(): sa.PrimaryKeyConstraint("id"), ) op.create_table( - "are_entreprise_etudiant", + "are_etudiants", sa.Column("id", sa.Integer(), nullable=False), sa.Column("entreprise_id", sa.Integer(), nullable=True), sa.Column("etudid", sa.Integer(), nullable=True), @@ -82,7 +82,7 @@ def upgrade(): sa.PrimaryKeyConstraint("id"), ) op.create_table( - "are_entreprise_offre", + "are_offres", sa.Column("id", sa.Integer(), nullable=False), sa.Column("entreprise_id", sa.Integer(), nullable=True), sa.Column( @@ -97,13 +97,14 @@ def upgrade(): sa.Column("missions", sa.Text(), nullable=True), sa.Column("duree", sa.Text(), nullable=True), sa.Column("expiration_date", sa.Date(), nullable=True), + sa.Column("expired", sa.Boolean(), nullable=True), sa.ForeignKeyConstraint( ["entreprise_id"], ["are_entreprises.id"], ondelete="cascade" ), sa.PrimaryKeyConstraint("id"), ) op.create_table( - "are_entreprise_envoi_offre", + "are_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), @@ -114,15 +115,13 @@ def upgrade(): server_default=sa.text("now()"), nullable=True, ), - sa.ForeignKeyConstraint( - ["offre_id"], ["are_entreprise_offre.id"], ondelete="cascade" - ), + sa.ForeignKeyConstraint(["offre_id"], ["are_offres.id"], ondelete="cascade"), sa.ForeignKeyConstraint(["receiver_id"], ["user.id"], ondelete="cascade"), sa.ForeignKeyConstraint(["sender_id"], ["user.id"], ondelete="cascade"), sa.PrimaryKeyConstraint("id"), ) op.create_table( - "are_entreprise_envoi_offre_etudiant", + "are_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), @@ -133,44 +132,29 @@ def upgrade(): server_default=sa.text("now()"), nullable=True, ), - sa.ForeignKeyConstraint( - ["offre_id"], ["are_entreprise_offre.id"], ondelete="cascade" - ), + sa.ForeignKeyConstraint(["offre_id"], ["are_offres.id"], ondelete="cascade"), sa.ForeignKeyConstraint(["receiver_id"], ["identite.id"], ondelete="cascade"), sa.ForeignKeyConstraint(["sender_id"], ["user.id"], ondelete="cascade"), sa.PrimaryKeyConstraint("id"), ) op.create_table( - "are_entreprise_offre_departement", + "are_offre_departement", sa.Column("id", sa.Integer(), nullable=False), sa.Column("offre_id", sa.Integer(), nullable=True), sa.Column("dept_id", sa.Integer(), nullable=True), sa.ForeignKeyConstraint(["dept_id"], ["departement.id"], ondelete="cascade"), - sa.ForeignKeyConstraint( - ["offre_id"], ["are_entreprise_offre.id"], ondelete="cascade" - ), + sa.ForeignKeyConstraint(["offre_id"], ["are_offres.id"], ondelete="cascade"), 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") - op.drop_index("ix_apc_competence_id_orebut", table_name="apc_competence") - op.create_index( - op.f("ix_apc_competence_id_orebut"), - "apc_competence", - ["id_orebut"], - unique=False, - ) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_index(op.f("ix_apc_competence_id_orebut"), table_name="apc_competence") - op.create_index( - "ix_apc_competence_id_orebut", "apc_competence", ["id_orebut"], unique=False - ) op.create_table( "entreprises", sa.Column( @@ -258,13 +242,13 @@ def downgrade(): ), sa.PrimaryKeyConstraint("id", name="entreprise_contact_pkey"), ) - op.drop_table("are_entreprise_offre_departement") - 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_offre_departement") + op.drop_table("are_envoi_offre_etudiant") + op.drop_table("are_envoi_offre") + op.drop_table("are_offres") + op.drop_table("are_etudiants") + op.drop_table("are_contacts") op.drop_table("are_preferences") + op.drop_table("are_logs") op.drop_table("are_entreprises") - op.drop_table("are_entreprise_log") # ### end Alembic commands ###