From 0220607caa17505c6f60d96a122047bfc2715b28 Mon Sep 17 00:00:00 2001 From: Arthur ZHU Date: Mon, 24 Jan 2022 19:02:16 +0100 Subject: [PATCH] =?UTF-8?q?ajout=20page=20offres=20expir=C3=A9es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/entreprises/routes.py | 30 +++++++++++++++++++ .../entreprises/fiche_entreprise.html | 1 + .../entreprises/offres_expirees.html | 14 +++++++++ 3 files changed, 45 insertions(+) create mode 100644 app/templates/entreprises/offres_expirees.html diff --git a/app/entreprises/routes.py b/app/entreprises/routes.py index 7618d164..51c693de 100644 --- a/app/entreprises/routes.py +++ b/app/entreprises/routes.py @@ -188,6 +188,36 @@ def offres(): ) +@bp.route("/fiche_entreprise//offres_expirees") +def offres_expirees(id): + entreprise = Entreprise.query.filter_by(id=id).first_or_404() + offres = entreprise.offres + offres_expirees_with_files = [] + for offre in offres: + if date.today() > offre.expiration_date: + files = [] + path = os.path.join( + Config.SCODOC_VAR_DIR, + "entreprises", + f"{offre.entreprise_id}", + f"{offre.id}", + ) + if os.path.exists(path): + for dir in glob.glob( + f"{path}/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9]" + ): + for file in glob.glob(f"{dir}/*"): + file = [os.path.basename(dir), os.path.basename(file)] + files.append(file) + offres_expirees_with_files.append([offre, files]) + return render_template( + "entreprises/offres_expirees.html", + title=("Offres expirées"), + entreprise=entreprise, + offres_expirees=offres_expirees_with_files, + ) + + @bp.route("/add_entreprise", methods=["GET", "POST"]) def add_entreprise(): """ diff --git a/app/templates/entreprises/fiche_entreprise.html b/app/templates/entreprises/fiche_entreprise.html index 9bb20a8a..8e03942d 100644 --- a/app/templates/entreprises/fiche_entreprise.html +++ b/app/templates/entreprises/fiche_entreprise.html @@ -71,6 +71,7 @@ Ajouter contact Ajouter historique + Voir les offres expirées {% endblock %} \ No newline at end of file diff --git a/app/templates/entreprises/offres_expirees.html b/app/templates/entreprises/offres_expirees.html new file mode 100644 index 00000000..50c1b7d7 --- /dev/null +++ b/app/templates/entreprises/offres_expirees.html @@ -0,0 +1,14 @@ +{# -*- mode: jinja-html -*- #} +{% extends 'base.html' %} + +{% block app_content %} +
+

Offres expirées de {{ entreprise.nom }}

+{% if offres_expirees %} + {% for offre in offres_expirees%} + Offre {{loop.index}} (ajouté le {{offre[0].date_ajout.strftime('%d/%m/%Y') }}) + {% include 'entreprises/_offre.html' %} + {% endfor %} +{% endif %} +
+{% endblock %} \ No newline at end of file