forked from ScoDoc/ScoDoc
affichage checkbox entreprises désactivés, activer
This commit is contained in:
parent
c0363f6bd1
commit
a5cec8e068
@ -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)
|
||||
|
@ -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/<int:id>", 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",
|
||||
)
|
||||
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
{% block app_content %}
|
||||
<h1>{{ title }}</h1>
|
||||
<br>
|
||||
<div style="color:red;">{{ info_message }}</div>
|
||||
<div>{{ info_message }}</div>
|
||||
<br>
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
|
@ -36,6 +36,12 @@
|
||||
|
||||
<div class="container" style="margin-bottom: 10px;">
|
||||
<h1>Liste des entreprises</h1>
|
||||
{% if form %}
|
||||
<form method="POST" action="">
|
||||
{{ form.hidden_tag() }}
|
||||
<input id="active" name="active" type="checkbox" onChange="form.submit()" {% if checked %} checked {% endif %}> <label for="active">Afficher les entreprises désactivés</label>
|
||||
</form>
|
||||
{% endif %}
|
||||
<table id="table-entreprises">
|
||||
<thead>
|
||||
<tr>
|
||||
@ -53,7 +59,7 @@
|
||||
<tbody>
|
||||
{% for entreprise in entreprises %}
|
||||
<tr>
|
||||
<td><a href="{{ url_for('entreprises.fiche_entreprise', id=entreprise.id) }}">{{ entreprise.siret }}</a></td>
|
||||
<td><a href="{{ url_for('entreprises.fiche_entreprise', id=entreprise.id) }}" {% if not entreprise.active %} style="color:red" {% endif %}>{{ entreprise.siret }}</a></td>
|
||||
<td>{{ entreprise.nom }}</td>
|
||||
<td>{{ entreprise.adresse }}</td>
|
||||
<td>{{ entreprise.codepostal }}</td>
|
||||
@ -67,7 +73,11 @@
|
||||
</a>
|
||||
<ul class="dropdown-menu pull-left">
|
||||
<li><a href="{{ url_for('entreprises.edit_entreprise', id=entreprise.id) }}">Modifier</a></li>
|
||||
{% if entreprise.active %}
|
||||
<li><a href="{{ url_for('entreprises.fiche_entreprise_desactiver', id=entreprise.id)}}" style="color:red">Désactiver</a></li>
|
||||
{% else %}
|
||||
<li><a href="{{ url_for('entreprises.fiche_entreprise_activer', id=entreprise.id)}}" style="color:blue">Activer</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
</td>
|
||||
|
@ -40,7 +40,11 @@
|
||||
<div>
|
||||
{% if current_user.has_permission(current_user.Permission.RelationsEntreprisesChange, None) %}
|
||||
<a class="btn btn-primary" href="{{ url_for('entreprises.edit_entreprise', id=entreprise.id) }}">Modifier</a>
|
||||
{% if entreprise.active %}
|
||||
<a class="btn btn-danger" href="{{ url_for('entreprises.fiche_entreprise_desactiver', id=entreprise.id) }}">Désactiver</a>
|
||||
{% else %}
|
||||
<a class="btn btn-success" href="{{ url_for('entreprises.fiche_entreprise_activer', id=entreprise.id) }}">Activer</a>
|
||||
{% endif %}
|
||||
<a class="btn btn-primary" href="{{ url_for('entreprises.add_site', id=entreprise.id) }}">Ajouter site</a>
|
||||
<a class="btn btn-primary" href="{{ url_for('entreprises.add_offre', id=entreprise.id) }}">Ajouter offre</a>
|
||||
{% endif %}
|
||||
|
Loading…
Reference in New Issue
Block a user