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,
|
BooleanField,
|
||||||
FieldList,
|
FieldList,
|
||||||
FormField,
|
FormField,
|
||||||
|
BooleanField,
|
||||||
)
|
)
|
||||||
from wtforms.validators import ValidationError, DataRequired, Email, Optional
|
from wtforms.validators import ValidationError, DataRequired, Email, Optional
|
||||||
from wtforms.widgets import ListWidget, CheckboxInput
|
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)
|
return StringField(label, validators=[Optional()], render_kw=render_kw)
|
||||||
|
|
||||||
|
|
||||||
|
class EntreprisesFilterForm(FlaskForm):
|
||||||
|
active = BooleanField("Afficher les entreprises désactivés")
|
||||||
|
|
||||||
|
|
||||||
class EntrepriseCreationForm(FlaskForm):
|
class EntrepriseCreationForm(FlaskForm):
|
||||||
siret = _build_string_field(
|
siret = _build_string_field(
|
||||||
"SIRET (*)",
|
"SIRET (*)",
|
||||||
@ -656,8 +661,10 @@ class SuppressionConfirmationForm(FlaskForm):
|
|||||||
|
|
||||||
class DesactivationConfirmationForm(FlaskForm):
|
class DesactivationConfirmationForm(FlaskForm):
|
||||||
notes_active = TextAreaField("Notes sur la désactivation", validators=[Optional()])
|
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):
|
class ValidationConfirmationForm(FlaskForm):
|
||||||
submit = SubmitField("Valider", render_kw=SUBMIT_MARGE)
|
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 import LOGS_LEN
|
||||||
from app.entreprises.forms import (
|
from app.entreprises.forms import (
|
||||||
|
ActivationConfirmationForm,
|
||||||
CorrespondantsCreationForm,
|
CorrespondantsCreationForm,
|
||||||
DesactivationConfirmationForm,
|
DesactivationConfirmationForm,
|
||||||
EntrepriseCreationForm,
|
EntrepriseCreationForm,
|
||||||
EntrepriseModificationForm,
|
EntrepriseModificationForm,
|
||||||
|
EntreprisesFilterForm,
|
||||||
SiteCreationForm,
|
SiteCreationForm,
|
||||||
SiteModificationForm,
|
SiteModificationForm,
|
||||||
SuppressionConfirmationForm,
|
SuppressionConfirmationForm,
|
||||||
@ -57,7 +59,7 @@ from sqlalchemy import text
|
|||||||
from werkzeug.utils import secure_filename
|
from werkzeug.utils import secure_filename
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/", methods=["GET"])
|
@bp.route("/", methods=["GET", "POST"])
|
||||||
@permission_required(Permission.RelationsEntreprisesView)
|
@permission_required(Permission.RelationsEntreprisesView)
|
||||||
def index():
|
def index():
|
||||||
"""
|
"""
|
||||||
@ -65,6 +67,21 @@ def index():
|
|||||||
"""
|
"""
|
||||||
entreprises = Entreprise.query.filter_by(visible=True, active=True)
|
entreprises = Entreprise.query.filter_by(visible=True, active=True)
|
||||||
logs = EntrepriseLog.query.order_by(EntrepriseLog.date.desc()).limit(LOGS_LEN).all()
|
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(
|
return render_template(
|
||||||
"entreprises/entreprises.html",
|
"entreprises/entreprises.html",
|
||||||
title="Entreprises",
|
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
|
La fiche entreprise comporte les informations de l'entreprise, les correspondants de l'entreprise et
|
||||||
les offres de l'entreprise.
|
les offres de l'entreprise.
|
||||||
"""
|
"""
|
||||||
entreprise = Entreprise.query.filter_by(
|
entreprise = Entreprise.query.filter_by(id=id, visible=True).first_or_404(
|
||||||
id=id, visible=True, active=True
|
description=f"fiche entreprise {id} inconnue"
|
||||||
).first_or_404(description=f"fiche entreprise {id} inconnue")
|
)
|
||||||
offres_with_files = []
|
offres_with_files = []
|
||||||
depts = are.get_depts()
|
depts = are.get_depts()
|
||||||
for offre in entreprise.offres:
|
for offre in entreprise.offres:
|
||||||
@ -430,21 +447,44 @@ def fiche_entreprise_desactiver(id):
|
|||||||
"""
|
"""
|
||||||
Permet de désactiver une entreprise
|
Permet de désactiver une entreprise
|
||||||
"""
|
"""
|
||||||
entreprise = Entreprise.query.filter_by(id=id, visible=True).first_or_404(
|
entreprise = Entreprise.query.filter_by(
|
||||||
description=f"entreprise {id} inconnue"
|
id=id, visible=True, active=True
|
||||||
)
|
).first_or_404(description=f"entreprise {id} inconnue")
|
||||||
form = DesactivationConfirmationForm()
|
form = DesactivationConfirmationForm()
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
entreprise.notes_active = form.notes_active.data.strip()
|
entreprise.notes_active = form.notes_active.data.strip()
|
||||||
entreprise.active = False
|
entreprise.active = False
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash("L'entreprise a été désactivé.")
|
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(
|
return render_template(
|
||||||
"entreprises/confirmation_form.html",
|
"entreprises/confirmation_form.html",
|
||||||
title="Désactiver entreprise",
|
title="Désactiver entreprise",
|
||||||
form=form,
|
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 %}
|
{% block app_content %}
|
||||||
<h1>{{ title }}</h1>
|
<h1>{{ title }}</h1>
|
||||||
<br>
|
<br>
|
||||||
<div style="color:red;">{{ info_message }}</div>
|
<div>{{ info_message }}</div>
|
||||||
<br>
|
<br>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
|
@ -36,6 +36,12 @@
|
|||||||
|
|
||||||
<div class="container" style="margin-bottom: 10px;">
|
<div class="container" style="margin-bottom: 10px;">
|
||||||
<h1>Liste des entreprises</h1>
|
<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">
|
<table id="table-entreprises">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@ -53,7 +59,7 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
{% for entreprise in entreprises %}
|
{% for entreprise in entreprises %}
|
||||||
<tr>
|
<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.nom }}</td>
|
||||||
<td>{{ entreprise.adresse }}</td>
|
<td>{{ entreprise.adresse }}</td>
|
||||||
<td>{{ entreprise.codepostal }}</td>
|
<td>{{ entreprise.codepostal }}</td>
|
||||||
@ -67,7 +73,11 @@
|
|||||||
</a>
|
</a>
|
||||||
<ul class="dropdown-menu pull-left">
|
<ul class="dropdown-menu pull-left">
|
||||||
<li><a href="{{ url_for('entreprises.edit_entreprise', id=entreprise.id) }}">Modifier</a></li>
|
<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>
|
<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>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
@ -40,7 +40,11 @@
|
|||||||
<div>
|
<div>
|
||||||
{% if current_user.has_permission(current_user.Permission.RelationsEntreprisesChange, None) %}
|
{% 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>
|
<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>
|
<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_site', id=entreprise.id) }}">Ajouter site</a>
|
||||||
<a class="btn btn-primary" href="{{ url_for('entreprises.add_offre', id=entreprise.id) }}">Ajouter offre</a>
|
<a class="btn btn-primary" href="{{ url_for('entreprises.add_offre', id=entreprise.id) }}">Ajouter offre</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
Loading…
Reference in New Issue
Block a user