ajout page historique, suite validation

This commit is contained in:
Arthur ZHU 2022-02-02 19:13:50 +01:00
parent d32d49ea4d
commit 3e21275518
9 changed files with 127 additions and 13 deletions

View File

@ -80,7 +80,7 @@ def logs():
@bp.route("/validation", methods=["GET"])
@permission_required(Permission.RelationsEntreprisesValidate)
def validation_entreprise():
def validation():
"""
Permet d'afficher une page avec la liste des entreprises a valider
"""
@ -166,6 +166,29 @@ def fiche_entreprise(id):
)
@bp.route("/logs/<int:id>", methods=["GET"])
@permission_required(Permission.RelationsEntreprisesView)
def logs_entreprise(id):
"""
Permet d'afficher les logs (toutes les entreprises)
"""
page = request.args.get("page", 1, type=int)
entreprise = Entreprise.query.filter_by(id=id, visible=True).first_or_404()
logs = (
EntrepriseLog.query.order_by(EntrepriseLog.date.desc())
.filter_by(object=id)
.paginate(page=page, per_page=20)
)
if logs is None:
abort(404)
return render_template(
"entreprises/logs_entreprise.html",
title=("Logs"),
logs=logs,
entreprise=entreprise,
)
@bp.route("/fiche_entreprise_validation/<int:id>", methods=["GET"])
@permission_required(Permission.RelationsEntreprisesValidate)
def fiche_entreprise_validation(id):
@ -281,15 +304,22 @@ def add_entreprise():
service=form.service.data.strip(),
)
db.session.add(contact)
nom_entreprise = f"<a href=/ScoDoc/entreprises/fiche_entreprise/{entreprise.id}>{entreprise.nom}</a>"
log = EntrepriseLog(
authenticated_user=current_user.user_name,
text=f"{nom_entreprise} - Création de la fiche entreprise ({entreprise.nom}) avec un contact",
)
db.session.add(log)
db.session.commit()
flash("L'entreprise a été ajouté à la liste.")
return redirect(url_for("entreprises.index"))
if current_user.has_permission(Permission.RelationsEntreprisesValidate, None):
entreprise.visible = True
nom_entreprise = f"<a href=/ScoDoc/entreprises/fiche_entreprise/{entreprise.id}>{entreprise.nom}</a>"
log = EntrepriseLog(
authenticated_user=current_user.user_name,
text=f"{nom_entreprise} - Création de la fiche entreprise ({entreprise.nom}) avec un contact",
)
db.session.add(log)
db.session.commit()
flash("L'entreprise a été ajouté à la liste.")
return redirect(url_for("entreprises.index"))
else:
entreprise.visible = False
db.session.commit()
flash("L'entreprise a été ajouté à la liste pour la validation.")
return redirect(url_for("entreprises.index"))
return render_template(
"entreprises/ajout_entreprise.html",
title=("Ajout entreprise avec contact"),
@ -398,8 +428,15 @@ def validate_entreprise(id):
entreprise = Entreprise.query.filter_by(id=id, visible=False).first_or_404()
if form.validate_on_submit():
entreprise.visible = True
nom_entreprise = f"<a href=/ScoDoc/entreprises/fiche_entreprise/{entreprise.id}>{entreprise.nom}</a>"
log = EntrepriseLog(
authenticated_user=current_user.user_name,
text=f"{nom_entreprise} - Validation de la fiche entreprise ({entreprise.nom}) avec un contact",
)
db.session.add(log)
db.session.commit()
return redirect(url_for("entreprises.fiche_entreprise", id=entreprise.id))
flash("L'entreprise a été validé et ajouté à la liste.")
return redirect(url_for("entreprises.index"))
return render_template(
"entreprises/validate_confirmation.html",
title=("Validation entreprise"),

View File

@ -1,3 +1,24 @@
.nav-entreprise>ul {
margin: 0;
padding: 0;
}
.nav-entreprise li{
list-style: none;
display: inline-block;
}
.nav-entreprise>ul>li>a {
text-decoration: none;
color: black;
padding: 15px;
}
.nav-entreprise>ul>li>a:hover {
color: red;
}
.btn-inverse {
color: #ffffff;
text-shadow: 0 -1px 0 rgb(0 0 0 / 25%);

View File

@ -2,6 +2,8 @@
{% extends 'base.html' %}
{% block app_content %}
{% include 'entreprises/nav.html' %}
{% if logs %}
<div class="container">
<h3>Dernières opérations <a href="{{ url_for('entreprises.logs') }}">Voir tout</a></h3>

View File

@ -2,6 +2,8 @@
{% extends 'base.html' %}
{% block app_content %}
{% include 'entreprises/nav.html' %}
{% if logs %}
<div class="container">
<h3>Dernières opérations <a href="{{ url_for('entreprises.logs') }}">Voir tout</a></h3>

View File

@ -2,6 +2,8 @@
{% extends 'base.html' %}
{% block app_content %}
{% include 'entreprises/nav.html' %}
{% if logs %}
<div class="container">
<h3>Dernières opérations</h3>
@ -36,7 +38,7 @@
<th>{{ entreprise.ville }}</th>
<th>{{ entreprise.pays }}</th>
<th>
<a class="btn btn-success" href="{{ url_for('entreprises.validate_entreprise', id=entreprise.id) }}">Valider</a>
<a class="btn btn-default" href="{{ url_for('entreprises.fiche_entreprise_validation', id=entreprise.id) }}">Voir</a>
</th>
</tr>
{% endfor %}

View File

@ -4,7 +4,7 @@
{% block app_content %}
{% if logs %}
<div class="container">
<h3>Dernières opérations sur cette fiche</h3>
<h3>Dernières opérations sur cette fiche <a href="{{ url_for('entreprises.logs_entreprise', id=entreprise.id) }}">Voir tout</a></h3>
<ul>
{% for log in logs %}
<li>

View File

@ -0,0 +1,37 @@
{# -*- mode: jinja-html -*- #}
{% extends 'base.html' %}
{% block app_content %}
<div class="container">
<h3>Dernières opérations - {{ entreprise.nom }}</h3>
<ul>
{% for log in logs.items %}
<li><span style="margin-right: 10px;">{{ log.date.strftime('%d %b %Hh%M') }}</span><span>{{ log.text|safe }} par {{ log.authenticated_user|get_nomcomplet }}</span></li>
{% endfor %}
</ul>
</div>
<div class="text-center">
<a href="{{ url_for('entreprises.logs_entreprise', id=entreprise.id, page=logs.prev_num) }}" class="btn btn-default {% if logs.page == 1 %}disabled{% endif %}">
&laquo;
</a>
{% for page_num in logs.iter_pages(left_edge=1, right_edge=1, left_current=1, right_current=2) %}
{% if page_num %}
{% if logs.page == page_num %}
<a href="{{ url_for('entreprises.logs_entreprise', id=entreprise.id, page=page_num) }}" class="btn btn-inverse">{{ page_num }}</a>
{% else %}
<a href="{{ url_for('entreprises.logs_entreprise', id=entreprise.id, page=page_num) }}" class="btn btn-default">{{ page_num }}</a>
{% endif %}
{% else %}
...
{% endif %}
{% endfor %}
<a href="{{ url_for('entreprises.logs_entreprise', id=entreprise.id, page=logs.next_num) }}" class="btn btn-default {% if logs.page == logs.pages %}disabled{% endif %}">
&raquo;
</a>
</div>
<p class="text-center">
Page {{ logs.page }} sur {{ logs.pages }}
</p>
{% endblock %}

View File

@ -0,0 +1,11 @@
{# -*- mode: jinja-html -*- #}
<nav class="nav-entreprise">
<ul>
<li><a href="{{ url_for('entreprises.index') }}">Entreprises</a></li>
<li><a href="{{ url_for('entreprises.contacts') }}">Contacts</a></li>
<li><a href="{{ url_for('entreprises.offres_recues') }}">Offres reçues</a></li>
{% if current_user.has_permission(current_user.Permission.RelationsEntreprisesValidate, None) %}
<li><a href="{{ url_for('entreprises.validation') }}">Entreprises à valider</a></li>
{% endif %}
</ul>
</nav>

View File

@ -2,6 +2,8 @@
{% extends 'base.html' %}
{% block app_content %}
{% include 'entreprises/nav.html' %}
<div class="container">
<h1>{{ title }}</h1>
{% if offres_recues %}