diff --git a/app/entreprises/routes.py b/app/entreprises/routes.py index 7618d1644..51c693def 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 9bb20a8a8..8e03942d4 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 000000000..50c1b7d76 --- /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