1
0
forked from ScoDoc/ScoDoc

supprime fichiers lors des suppressions, correctifs

This commit is contained in:
Arthur ZHU 2022-02-08 16:40:32 +01:00
parent 442e1a35c9
commit 6d7a7a7c4b
13 changed files with 152 additions and 92 deletions

View File

@ -1,4 +1,5 @@
import os import os
from queue import Empty
from config import Config from config import Config
from datetime import datetime, date from datetime import datetime, date
import glob import glob
@ -75,7 +76,11 @@ def logs():
logs = EntrepriseLog.query.order_by(EntrepriseLog.date.desc()).paginate( logs = EntrepriseLog.query.order_by(EntrepriseLog.date.desc()).paginate(
page=page, per_page=20 page=page, per_page=20
) )
return render_template("entreprises/logs.html", title=("Logs"), logs=logs) return render_template(
"entreprises/logs.html",
title=("Logs"),
logs=logs,
)
@bp.route("/validation", methods=["GET"]) @bp.route("/validation", methods=["GET"])
@ -107,7 +112,10 @@ def contacts():
) )
logs = EntrepriseLog.query.order_by(EntrepriseLog.date.desc()).limit(LOGS_LEN).all() logs = EntrepriseLog.query.order_by(EntrepriseLog.date.desc()).limit(LOGS_LEN).all()
return render_template( return render_template(
"entreprises/contacts.html", title=("Contacts"), contacts=contacts, logs=logs "entreprises/contacts.html",
title=("Contacts"),
contacts=contacts,
logs=logs,
) )
@ -392,7 +400,9 @@ def edit_entreprise(id):
form.ville.data = entreprise.ville form.ville.data = entreprise.ville
form.pays.data = entreprise.pays form.pays.data = entreprise.pays
return render_template( return render_template(
"entreprises/form.html", title=("Modification entreprise"), form=form "entreprises/form.html",
title=("Modification entreprise"),
form=form,
) )
@ -406,6 +416,14 @@ def delete_entreprise(id):
form = SuppressionConfirmationForm() form = SuppressionConfirmationForm()
if form.validate_on_submit(): if form.validate_on_submit():
db.session.delete(entreprise) db.session.delete(entreprise)
# supprime les fichiers attachés aux offres
path = os.path.join(
Config.SCODOC_VAR_DIR,
"entreprises",
f"{entreprise.id}",
)
if os.path.isdir(path):
shutil.rmtree(path)
log = EntrepriseLog( log = EntrepriseLog(
authenticated_user=current_user.user_name, authenticated_user=current_user.user_name,
object=entreprise.id, object=entreprise.id,
@ -484,7 +502,11 @@ def add_offre(id):
db.session.commit() db.session.commit()
flash("L'offre a été ajouté à la fiche entreprise.") flash("L'offre a été ajouté à la fiche entreprise.")
return redirect(url_for("entreprises.fiche_entreprise", id=entreprise.id)) return redirect(url_for("entreprises.fiche_entreprise", id=entreprise.id))
return render_template("entreprises/form.html", title=("Ajout offre"), form=form) return render_template(
"entreprises/form.html",
title=("Ajout offre"),
form=form,
)
@bp.route("/edit_offre/<int:id>", methods=["GET", "POST"]) @bp.route("/edit_offre/<int:id>", methods=["GET", "POST"])
@ -536,7 +558,9 @@ def edit_offre(id):
form.expiration_date.data = offre.expiration_date form.expiration_date.data = offre.expiration_date
form.depts.data = offre_depts_list form.depts.data = offre_depts_list
return render_template( return render_template(
"entreprises/form.html", title=("Modification offre"), form=form "entreprises/form.html",
title=("Modification offre"),
form=form,
) )
@ -551,6 +575,14 @@ def delete_offre(id):
form = SuppressionConfirmationForm() form = SuppressionConfirmationForm()
if form.validate_on_submit(): if form.validate_on_submit():
db.session.delete(offre) db.session.delete(offre)
path = os.path.join(
Config.SCODOC_VAR_DIR,
"entreprises",
f"{entreprise_id}",
f"{offre.id}",
)
if os.path.isdir(path):
shutil.rmtree(path)
log = EntrepriseLog( log = EntrepriseLog(
authenticated_user=current_user.user_name, authenticated_user=current_user.user_name,
object=offre.entreprise_id, object=offre.entreprise_id,
@ -561,7 +593,9 @@ def delete_offre(id):
flash("L'offre a été supprimé de la fiche entreprise.") flash("L'offre a été supprimé de la fiche entreprise.")
return redirect(url_for("entreprises.fiche_entreprise", id=entreprise_id)) return redirect(url_for("entreprises.fiche_entreprise", id=entreprise_id))
return render_template( return render_template(
"entreprises/delete_confirmation.html", title=("Supression offre"), form=form "entreprises/delete_confirmation.html",
title=("Supression offre"),
form=form,
) )
@ -593,7 +627,11 @@ def add_contact(id):
db.session.commit() db.session.commit()
flash("Le contact a été ajouté à la fiche entreprise.") flash("Le contact a été ajouté à la fiche entreprise.")
return redirect(url_for("entreprises.fiche_entreprise", id=entreprise.id)) return redirect(url_for("entreprises.fiche_entreprise", id=entreprise.id))
return render_template("entreprises/form.html", title=("Ajout contact"), form=form) return render_template(
"entreprises/form.html",
title=("Ajout contact"),
form=form,
)
@bp.route("/edit_contact/<int:id>", methods=["GET", "POST"]) @bp.route("/edit_contact/<int:id>", methods=["GET", "POST"])
@ -633,7 +671,9 @@ def edit_contact(id):
form.poste.data = contact.poste form.poste.data = contact.poste
form.service.data = contact.service form.service.data = contact.service
return render_template( return render_template(
"entreprises/form.html", title=("Modification contact"), form=form "entreprises/form.html",
title=("Modification contact"),
form=form,
) )
@ -667,7 +707,9 @@ def delete_contact(id):
flash("Le contact a été supprimé de la fiche entreprise.") flash("Le contact a été supprimé de la fiche entreprise.")
return redirect(url_for("entreprises.fiche_entreprise", id=entreprise_id)) return redirect(url_for("entreprises.fiche_entreprise", id=entreprise_id))
return render_template( return render_template(
"entreprises/delete_confirmation.html", title=("Supression contact"), form=form "entreprises/delete_confirmation.html",
title=("Supression contact"),
form=form,
) )
@ -708,7 +750,9 @@ def add_historique(id):
flash("L'étudiant a été ajouté sur la fiche entreprise.") flash("L'étudiant a été ajouté sur la fiche entreprise.")
return redirect(url_for("entreprises.fiche_entreprise", id=entreprise.id)) return redirect(url_for("entreprises.fiche_entreprise", id=entreprise.id))
return render_template( return render_template(
"entreprises/ajout_historique.html", title=("Ajout historique"), form=form "entreprises/ajout_historique.html",
title=("Ajout historique"),
form=form,
) )
@ -738,7 +782,9 @@ def envoyer_offre(id):
flash(f"L'offre a été envoyé à {responsable.get_nomplogin()}.") flash(f"L'offre a été envoyé à {responsable.get_nomplogin()}.")
return redirect(url_for("entreprises.fiche_entreprise", id=offre.entreprise_id)) return redirect(url_for("entreprises.fiche_entreprise", id=offre.entreprise_id))
return render_template( return render_template(
"entreprises/envoi_offre_form.html", title=("Envoyer une offre"), form=form "entreprises/envoi_offre_form.html",
title=("Envoyer une offre"),
form=form,
) )
@ -840,6 +886,9 @@ def get_import_entreprises_file_sample():
@bp.route("/import_entreprises", methods=["GET", "POST"]) @bp.route("/import_entreprises", methods=["GET", "POST"])
@permission_required(Permission.RelationsEntreprisesExport) @permission_required(Permission.RelationsEntreprisesExport)
def import_entreprises(): def import_entreprises():
"""
Permet d'importer des entreprises a l'aide d'un fichier excel (.xlsx)
"""
form = ImportEntreprisesForm() form = ImportEntreprisesForm()
if form.validate_on_submit(): if form.validate_on_submit():
path = os.path.join(Config.SCODOC_VAR_DIR, "tmp") path = os.path.join(Config.SCODOC_VAR_DIR, "tmp")
@ -974,7 +1023,9 @@ def add_offre_file(offre_id):
flash("Le fichier a été ajouté a l'offre.") flash("Le fichier a été ajouté a l'offre.")
return redirect(url_for("entreprises.fiche_entreprise", id=offre.entreprise_id)) return redirect(url_for("entreprises.fiche_entreprise", id=offre.entreprise_id))
return render_template( return render_template(
"entreprises/form.html", title=("Ajout fichier à une offre"), form=form "entreprises/form.html",
title=("Ajout fichier à une offre"),
form=form,
) )

View File

@ -3,7 +3,7 @@
{% import 'bootstrap/wtf.html' as wtf %} {% import 'bootstrap/wtf.html' as wtf %}
{% block app_content %} {% block app_content %}
<h1>{{ title }}</h1> <h1>Ajout entreprise avec contact</h1>
<br> <br>
<div class="row"> <div class="row">
<div class="col-md-4"> <div class="col-md-4">

View File

@ -9,7 +9,7 @@
{% endblock %} {% endblock %}
{% block app_content %} {% block app_content %}
<h1>{{ title }}</h1> <h1>Ajout historique</h1>
<br> <br>
<div class="row"> <div class="row">
<div class="col-md-4"> <div class="col-md-4">

View File

@ -75,7 +75,7 @@
Page {{ contacts.page }} sur {{ contacts.pages }} Page {{ contacts.page }} sur {{ contacts.pages }}
</p> </p>
{% else %} {% else %}
<div>Aucun contact présent dans la base</div> <div>Aucun contact présent dans la base</div>
{% endif %} {% endif %}
</div> </div>
{% endblock %} {% endblock %}

View File

@ -95,7 +95,7 @@
Page {{ entreprises.page }} sur {{ entreprises.pages }} Page {{ entreprises.page }} sur {{ entreprises.pages }}
</p> </p>
{% else %} {% else %}
<div>Aucune entreprise présent dans la base</div> <div>Aucune entreprise présent dans la base</div>
{% endif %} {% endif %}
</div> </div>
{% endblock %} {% endblock %}

View File

@ -43,10 +43,9 @@
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>
{% else %}
<div>Aucune entreprise à valider</div>
<br>
</div> </div>
{% else %}
<div>Aucune entreprise à valider</div>
{% endif %} {% endif %}
</div> </div>
{% endblock %} {% endblock %}

View File

@ -9,7 +9,7 @@
{% endblock %} {% endblock %}
{% block app_content %} {% block app_content %}
<h1>{{ title }}</h1> <h1>Envoyer une offre</h1>
<br> <br>
<div class="row"> <div class="row">
<div class="col-md-4"> <div class="col-md-4">

View File

@ -24,8 +24,12 @@
<div class="contact"> <div class="contact">
Nom : {{ contact.nom }}<br> Nom : {{ contact.nom }}<br>
Prénom : {{ contact.prenom }}<br> Prénom : {{ contact.prenom }}<br>
{% if contact.telephone %}
Téléphone : {{ contact.telephone }}<br> Téléphone : {{ contact.telephone }}<br>
{% endif %}
{% if contact.mail %}
Mail : {{ contact.mail }}<br> Mail : {{ contact.mail }}<br>
{% endif %}
{% if contact.poste %} {% if contact.poste %}
Poste : {{ contact.poste }}<br> Poste : {{ contact.poste }}<br>
{% endif %} {% endif %}

View File

@ -7,7 +7,7 @@
{% endblock %} {% endblock %}
{% block app_content %} {% block app_content %}
<h1>{{ title }}</h1> <h1>Importation entreprises</h1>
<br> <br>
<div> <div>
<a href="{{ url_for('entreprises.get_import_entreprises_file_sample') }}">Obtenir la feuille excel à remplir</a> <a href="{{ url_for('entreprises.get_import_entreprises_file_sample') }}">Obtenir la feuille excel à remplir</a>

View File

@ -4,34 +4,40 @@
{% block app_content %} {% block app_content %}
<div class="container"> <div class="container">
<h3>Dernières opérations</h3> <h3>Dernières opérations</h3>
<ul> {% if logs.items %}
{% for log in logs.items %} <ul>
<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> {% for log in logs.items %}
{% endfor %} <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>
</ul> {% endfor %}
</ul>
<div class="text-center">
<a href="{{ url_for('entreprises.logs', 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', page=page_num) }}" class="btn btn-inverse">{{ page_num }}</a>
{% else %}
<a href="{{ url_for('entreprises.logs', page=page_num) }}" class="btn btn-default">{{ page_num }}</a>
{% endif %}
{% else %}
...
{% endif %}
{% endfor %}
<a href="{{ url_for('entreprises.logs', 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>
{% else %}
<div>Aucune opération</div>
{% endif %}
</div> </div>
<div class="text-center">
<a href="{{ url_for('entreprises.logs', 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', page=page_num) }}" class="btn btn-inverse">{{ page_num }}</a>
{% else %}
<a href="{{ url_for('entreprises.logs', page=page_num) }}" class="btn btn-default">{{ page_num }}</a>
{% endif %}
{% else %}
...
{% endif %}
{% endfor %}
<a href="{{ url_for('entreprises.logs', 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 %} {% endblock %}

View File

@ -4,34 +4,39 @@
{% block app_content %} {% block app_content %}
<div class="container"> <div class="container">
<h3>Dernières opérations - {{ entreprise.nom }}</h3> <h3>Dernières opérations - {{ entreprise.nom }}</h3>
{% if logs.items %}
<ul> <ul>
{% for log in logs.items %} {% 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> <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 %} {% endfor %}
</ul> </ul>
<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>
{% else %}
<div>Aucune opération</div>
{% endif %}
</div> </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 %} {% endblock %}

View File

@ -5,31 +5,26 @@
{% include 'entreprises/nav.html' %} {% include 'entreprises/nav.html' %}
<div class="container"> <div class="container">
<h1>{{ title }}</h1> <h1>Offres reçues</h1>
{% if offres_recues %} {% if offres_recues %}
<div class="table-responsive">
<div>
{% for offre in offres_recues %} {% for offre in offres_recues %}
<div class="offre"> <div class="offre">
<div> <div>
Envoyé le {{ offre[0].date_envoi.strftime('%d %B %Y à %H:%M') }} par {{ offre[0].sender_id|get_nomcomplet_by_id }}<br> Envoyé le {{ offre[0].date_envoi.strftime('%d %B %Y à %H:%M') }} par {{ offre[0].sender_id|get_nomcomplet_by_id }}<br>
Intitulé : {{ offre[1].intitule }}<br> Intitulé : {{ offre[1].intitule }}<br>
Description : {{ offre[1].description }}<br> Description : {{ offre[1].description }}<br>
Type de l'offre : {{ offre[1].type_offre }}<br> Type de l'offre : {{ offre[1].type_offre }}<br>
Missions : {{ offre[1].missions }}<br> Missions : {{ offre[1].missions }}<br>
Durée : {{ offre[1].duree }}<br> Durée : {{ offre[1].duree }}<br>
{% for fichier in offre[2] %} {% for fichier in offre[2] %}
<a href="{{ url_for('entreprises.get_offre_file', entreprise_id=offre[1].entreprise_id, offre_id=offre[1].id, filedir=fichier[0], filename=fichier[1] )}}">{{ fichier[1] }}</a><br> <a href="{{ url_for('entreprises.get_offre_file', entreprise_id=offre[1].entreprise_id, offre_id=offre[1].id, filedir=fichier[0], filename=fichier[1] )}}">{{ fichier[1] }}</a><br>
{% endfor %} {% endfor %}
</div>
</div> </div>
{% endfor %}
</div> </div>
<br> {% endfor %}
{% else %} {% else %}
<div>Aucune offre reçue</div> <div>Aucune offre reçue</div>
</div>
{% endif %} {% endif %}
</div> </div>
{% endblock %} {% endblock %}

View File

@ -3,7 +3,7 @@
{% import 'bootstrap/wtf.html' as wtf %} {% import 'bootstrap/wtf.html' as wtf %}
{% block app_content %} {% block app_content %}
<h1>{{ title }}</h1> <h1>Validation entreprise</h1>
<br> <br>
<div style="color:green;">Cliquez sur le bouton Valider pour confirmer votre validation</div> <div style="color:green;">Cliquez sur le bouton Valider pour confirmer votre validation</div>
<br> <br>