diff --git a/app/entreprises/routes.py b/app/entreprises/routes.py index 8ec54394..5135470e 100644 --- a/app/entreprises/routes.py +++ b/app/entreprises/routes.py @@ -45,6 +45,7 @@ import app.scodoc.sco_utils as scu from app import db from sqlalchemy import text +from app.models.departements import Departement from werkzeug.utils import secure_filename @@ -120,6 +121,21 @@ def contacts(): ) +# temp +def get_dept_id(acronym): + dept = Departement.query.filter_by(acronym=acronym).first() + if dept is not None: + return dept.id + return None + + +def check_offre_dept(depts, offre_depts): + for offre_dept in offre_depts: + if offre_dept.dept_id in depts: + return True + return False + + @bp.route("/fiche_entreprise/", methods=["GET"]) @permission_required(Permission.RelationsEntreprisesView) def fiche_entreprise(id): @@ -131,26 +147,32 @@ def fiche_entreprise(id): """ entreprise = Entreprise.query.filter_by(id=id, visible=True).first_or_404() offres_with_files = [] + depts = [] + for role in current_user.user_roles: + dept_id = get_dept_id(role.dept) + if dept_id is not None: + depts.append(dept_id) for offre in entreprise.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) offre_depts = EntrepriseOffreDepartement.query.filter_by( offre_id=offre.id ).all() - offres_with_files.append([offre, files, offre_depts]) + if not offre_depts or check_offre_dept(depts, offre_depts): + 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_with_files.append([offre, files, offre_depts]) contacts = entreprise.contacts[:] logs = ( EntrepriseLog.query.order_by(EntrepriseLog.date.desc()) @@ -465,6 +487,26 @@ def validate_entreprise(id): ) +@bp.route("/delete_validation_entreprise/", methods=["GET", "POST"]) +@permission_required(Permission.RelationsEntreprisesValidate) +def delete_validation_entreprise(id): + """ + Permet de supprimer une entreprise en attente de validation avec une formulaire de validation + """ + entreprise = Entreprise.query.filter_by(id=id, visible=False).first_or_404() + form = SuppressionConfirmationForm() + if form.validate_on_submit(): + db.session.delete(entreprise) + db.session.commit() + flash("L'entreprise a été supprimé de la liste des entreprise à valider.") + return redirect(url_for("entreprises.validation")) + return render_template( + "entreprises/delete_confirmation.html", + title="Supression entreprise", + form=form, + ) + + @bp.route("/add_offre/", methods=["GET", "POST"]) @permission_required(Permission.RelationsEntreprisesChange) def add_offre(id): @@ -598,6 +640,17 @@ def delete_offre(id): ) +@bp.route("/delete_offre_recue/", methods=["GET", "POST"]) +@permission_required(Permission.RelationsEntreprisesView) +def delete_offre_recue(id): + offre_recue = EntrepriseEnvoiOffre.query.filter_by( + id=id, receiver_id=current_user.id + ).first_or_404() + db.session.delete(offre_recue) + db.session.commit() + return redirect(url_for("entreprises.offres_recues")) + + @bp.route("/add_contact/", methods=["GET", "POST"]) @permission_required(Permission.RelationsEntreprisesChange) def add_contact(id): @@ -954,6 +1007,11 @@ def import_entreprises(): if len(entreprises_import) > 0: for entreprise in entreprises_import: db.session.add(entreprise) + log = EntrepriseLog( + authenticated_user=current_user.user_name, + text=f"Importation de {len(entreprises_import)} entreprise(s)", + ) + db.session.add(log) db.session.commit() flash(f"Importation réussie de {len(entreprises_import)} entreprise(s)") return render_template( @@ -1113,6 +1171,11 @@ def import_contacts(): if len(contacts_import) > 0: for contact in contacts_import: db.session.add(contact) + log = EntrepriseLog( + authenticated_user=current_user.user_name, + text=f"Importation de {len(contacts_import)} contact(s)", + ) + db.session.add(log) db.session.commit() flash(f"Importation réussie de {len(contacts_import)} contact(s)") return render_template( diff --git a/app/static/css/entreprises.css b/app/static/css/entreprises.css index 8883fb9e..d2dc5cf5 100644 --- a/app/static/css/entreprises.css +++ b/app/static/css/entreprises.css @@ -75,9 +75,14 @@ padding-left: 10px; } -.offre_depts { +.offre-depts { display: inline-block; border: black solid 2px; border-radius: 5px; padding: 1px; +} + +.offre-recue { + display: flex; + justify-content: space-between; } \ No newline at end of file diff --git a/app/templates/entreprises/_offre.html b/app/templates/entreprises/_offre.html index 8e1f56cc..0176ddd2 100644 --- a/app/templates/entreprises/_offre.html +++ b/app/templates/entreprises/_offre.html @@ -7,7 +7,7 @@ Missions : {{ offre[0].missions }}
Durée : {{ offre[0].duree }}
{% if offre[2] %} - Département(s) : {% for offre_dept in offre[2] %}
{{ offre_dept.dept_id|get_dept_acronym }}
{% endfor %}
+ Département(s) : {% for offre_dept in offre[2] %}
{{ offre_dept.dept_id|get_dept_acronym }}
{% endfor %}
{% endif %} {% for fichier in offre[1] %} {{ fichier[1] }} diff --git a/app/templates/entreprises/fiche_entreprise_validation.html b/app/templates/entreprises/fiche_entreprise_validation.html index 9d67ac83..072461b4 100644 --- a/app/templates/entreprises/fiche_entreprise_validation.html +++ b/app/templates/entreprises/fiche_entreprise_validation.html @@ -44,6 +44,7 @@ {% endblock %} \ No newline at end of file diff --git a/app/templates/entreprises/offres_recues.html b/app/templates/entreprises/offres_recues.html index 63bbdb65..e4de166e 100644 --- a/app/templates/entreprises/offres_recues.html +++ b/app/templates/entreprises/offres_recues.html @@ -8,7 +8,7 @@

Offres reçues

{% if offres_recues %} {% for offre in offres_recues %} -
+
Envoyé le {{ offre[0].date_envoi.strftime('%d %B %Y à %H:%M') }} par {{ offre[0].sender_id|get_nomcomplet_by_id }}
Intitulé : {{ offre[1].intitule }}
@@ -18,9 +18,12 @@ Durée : {{ offre[1].duree }}
{% for fichier in offre[2] %} - {{ fichier[1] }}
+ {{ fichier[1] }}
{% endfor %}
+
+ supprimer +
{% endfor %} {% else %}