From a5cec8e06827fa237c0197732683afab2973a5c8 Mon Sep 17 00:00:00 2001 From: Arthur ZHU Date: Mon, 2 May 2022 14:36:39 +0200 Subject: [PATCH] =?UTF-8?q?affichage=20checkbox=20entreprises=20d=C3=A9sac?= =?UTF-8?q?tiv=C3=A9s,=20activer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/entreprises/forms.py | 9 ++- app/entreprises/routes.py | 58 ++++++++++++++++--- .../entreprises/confirmation_form.html | 2 +- app/templates/entreprises/entreprises.html | 12 +++- .../entreprises/fiche_entreprise.html | 4 ++ 5 files changed, 73 insertions(+), 12 deletions(-) diff --git a/app/entreprises/forms.py b/app/entreprises/forms.py index 610aa3608..f898e0e4a 100644 --- a/app/entreprises/forms.py +++ b/app/entreprises/forms.py @@ -42,6 +42,7 @@ from wtforms import ( BooleanField, FieldList, FormField, + BooleanField, ) from wtforms.validators import ValidationError, DataRequired, Email, Optional from wtforms.widgets import ListWidget, CheckboxInput @@ -70,6 +71,10 @@ def _build_string_field(label, required=True, render_kw=None): return StringField(label, validators=[Optional()], render_kw=render_kw) +class EntreprisesFilterForm(FlaskForm): + active = BooleanField("Afficher les entreprises désactivés") + + class EntrepriseCreationForm(FlaskForm): siret = _build_string_field( "SIRET (*)", @@ -656,8 +661,10 @@ class SuppressionConfirmationForm(FlaskForm): class DesactivationConfirmationForm(FlaskForm): notes_active = TextAreaField("Notes sur la désactivation", validators=[Optional()]) - submit = SubmitField("Désactiver", render_kw=SUBMIT_MARGE) + submit = SubmitField("Modifier", render_kw=SUBMIT_MARGE) +class ActivationConfirmationForm(FlaskForm): + submit = SubmitField("Modifier", render_kw=SUBMIT_MARGE) class ValidationConfirmationForm(FlaskForm): submit = SubmitField("Valider", render_kw=SUBMIT_MARGE) diff --git a/app/entreprises/routes.py b/app/entreprises/routes.py index 447484a9a..1607bc665 100644 --- a/app/entreprises/routes.py +++ b/app/entreprises/routes.py @@ -12,10 +12,12 @@ from app.decorators import permission_required from app.entreprises import LOGS_LEN from app.entreprises.forms import ( + ActivationConfirmationForm, CorrespondantsCreationForm, DesactivationConfirmationForm, EntrepriseCreationForm, EntrepriseModificationForm, + EntreprisesFilterForm, SiteCreationForm, SiteModificationForm, SuppressionConfirmationForm, @@ -57,7 +59,7 @@ from sqlalchemy import text from werkzeug.utils import secure_filename -@bp.route("/", methods=["GET"]) +@bp.route("/", methods=["GET", "POST"]) @permission_required(Permission.RelationsEntreprisesView) def index(): """ @@ -65,6 +67,21 @@ def index(): """ entreprises = Entreprise.query.filter_by(visible=True, active=True) logs = EntrepriseLog.query.order_by(EntrepriseLog.date.desc()).limit(LOGS_LEN).all() + if current_user.has_permission(Permission.RelationsEntreprisesChange, None): + form = EntreprisesFilterForm() + checked = False + if request.method == "POST": + checked = form.active.data + if checked: + entreprises = Entreprise.query.filter_by(visible=True) + return render_template( + "entreprises/entreprises.html", + title="Entreprises", + entreprises=entreprises, + logs=logs, + form=form, + checked=checked, + ) return render_template( "entreprises/entreprises.html", title="Entreprises", @@ -134,9 +151,9 @@ def fiche_entreprise(id): La fiche entreprise comporte les informations de l'entreprise, les correspondants de l'entreprise et les offres de l'entreprise. """ - entreprise = Entreprise.query.filter_by( - id=id, visible=True, active=True - ).first_or_404(description=f"fiche entreprise {id} inconnue") + entreprise = Entreprise.query.filter_by(id=id, visible=True).first_or_404( + description=f"fiche entreprise {id} inconnue" + ) offres_with_files = [] depts = are.get_depts() for offre in entreprise.offres: @@ -430,21 +447,44 @@ def fiche_entreprise_desactiver(id): """ Permet de désactiver une entreprise """ - entreprise = Entreprise.query.filter_by(id=id, visible=True).first_or_404( - description=f"entreprise {id} inconnue" - ) + entreprise = Entreprise.query.filter_by( + id=id, visible=True, active=True + ).first_or_404(description=f"entreprise {id} inconnue") form = DesactivationConfirmationForm() if form.validate_on_submit(): entreprise.notes_active = form.notes_active.data.strip() entreprise.active = False db.session.commit() flash("L'entreprise a été désactivé.") - return redirect(url_for("entreprises.index")) + return redirect(url_for("entreprises.fiche_entreprise", id=entreprise.id)) return render_template( "entreprises/confirmation_form.html", title="Désactiver entreprise", form=form, - info_message="Cliquez sur le bouton Désactiver pour confirmer la désactivation", + info_message="Cliquez sur le bouton Modifier pour confirmer la désactivation", + ) + + +@bp.route("/fiche_entreprise/activer/", methods=["GET", "POST"]) +@permission_required(Permission.RelationsEntreprisesChange) +def fiche_entreprise_activer(id): + """ + Permet d'activer une entreprise + """ + entreprise = Entreprise.query.filter_by( + id=id, visible=True, active=False + ).first_or_404(description=f"entreprise {id} inconnue") + form = ActivationConfirmationForm() + if form.validate_on_submit(): + entreprise.active = True + db.session.commit() + flash("L'entreprise a été activé.") + return redirect(url_for("entreprises.fiche_entreprise", id=entreprise.id)) + return render_template( + "entreprises/confirmation_form.html", + title="Activer entreprise", + form=form, + info_message="Cliquez sur le bouton Modifier pour confirmer l'activaction", ) diff --git a/app/templates/entreprises/confirmation_form.html b/app/templates/entreprises/confirmation_form.html index fb8737887..5de63ba06 100644 --- a/app/templates/entreprises/confirmation_form.html +++ b/app/templates/entreprises/confirmation_form.html @@ -5,7 +5,7 @@ {% block app_content %}

{{ title }}


-
{{ info_message }}
+
{{ info_message }}

diff --git a/app/templates/entreprises/entreprises.html b/app/templates/entreprises/entreprises.html index f6d08cec4..90ddd8ae8 100644 --- a/app/templates/entreprises/entreprises.html +++ b/app/templates/entreprises/entreprises.html @@ -36,6 +36,12 @@

Liste des entreprises

+ {% if form %} +
+ {{ form.hidden_tag() }} + +
+ {% endif %} @@ -53,7 +59,7 @@ {% for entreprise in entreprises %} - + @@ -67,7 +73,11 @@ diff --git a/app/templates/entreprises/fiche_entreprise.html b/app/templates/entreprises/fiche_entreprise.html index 787bc4839..eba36af24 100644 --- a/app/templates/entreprises/fiche_entreprise.html +++ b/app/templates/entreprises/fiche_entreprise.html @@ -40,7 +40,11 @@
{% if current_user.has_permission(current_user.Permission.RelationsEntreprisesChange, None) %} Modifier + {% if entreprise.active %} Désactiver + {% else %} + Activer + {% endif %} Ajouter site Ajouter offre {% endif %}
{{ entreprise.siret }}{{ entreprise.siret }} {{ entreprise.nom }} {{ entreprise.adresse }} {{ entreprise.codepostal }}