petitscours: ajout d'un bouton 'marquer comme traitée' pour les demandes sans propositions

This commit is contained in:
LeSeulArtichaut 2024-12-11 17:39:43 +01:00
parent 2126224e15
commit e357f57d61
2 changed files with 63 additions and 48 deletions

View file

@ -9,12 +9,14 @@
</h2> </h2>
{% include "petitscours/details_demande_infos.html" %} {% include "petitscours/details_demande_infos.html" %}
<hr /> <hr />
{% if errors %} {% if errors %}
<div class="error"> <div class="error">
Attention: Attention:
<ul>{% for error in errors %}<li>{{ error }}</li>{% endfor %}</ul> <ul>{% for error in errors %}<li>{{ error }}</li>{% endfor %}</ul>
</div> </div>
{% endif %} {% endif %}
{% if unsatisfied %} {% if unsatisfied %}
<div class="error"> <div class="error">
Attention: Impossible de trouver des propositions pour les matières suivantes: Attention: Impossible de trouver des propositions pour les matières suivantes:
@ -23,9 +25,12 @@
</ul> </ul>
</div> </div>
{% endif %} {% endif %}
{% if proposals %}
<form method="post"> <form method="post">
{% csrf_token %} {% csrf_token %}
{% if redo %}<input type="hidden" name="redo" value="1" />{% endif %}
{% if proposals %}
Propositions: Propositions:
<ul> <ul>
{% for proposeduser, matieres in proposed_for %} {% for proposeduser, matieres in proposed_for %}
@ -46,13 +51,16 @@
<pre style="margin-top: 15px;">{{ content|safe }}</pre> <pre style="margin-top: 15px;">{{ content|safe }}</pre>
{% endwith %} {% endwith %}
<input type="hidden" name="attribdata" value="{{ attribdata }}" /> <input type="hidden" name="attribdata" value="{{ attribdata }}" />
{% if redo %}<input type="hidden" name="redo" value="1" />{% endif %}
<input class="btn btn-primary pull-right" type="submit" value="Valider le {% if redo %}re{% endif %}traitement de la demande" /> <input class="btn btn-primary pull-right" type="submit" value="Valider le {% if redo %}re{% endif %}traitement de la demande" />
</form> </form>
{% else %} {% else %}
<h3>Impossible de trouver des propositions pour cette demande</h3> <h3>Impossible de trouver des propositions pour cette demande</h3>
<div class="error" style="font-size: 1.6em; margin-top: 10px;">Traitement manuel obligatoire !</div> <div class="error" style="font-size: 1.6em; margin-top: 10px;">Traitement manuel obligatoire !</div>
<input type="hidden" name="manual" value="1" />
<input class="btn btn-primary pull-right" type="submit" value="Marquer comme traitée" />
{% endif %} {% endif %}
</form>
<p> <p>
<a href="{% url 'petits-cours-demandes-list' %}">Retour à la liste des demandes</a> <a href="{% url 'petits-cours-demandes-list' %}">Retour à la liste des demandes</a>
</p> </p>

View file

@ -185,11 +185,27 @@ def _traitement_other(request, demande, redo):
def _traitement_post(request, demande): def _traitement_post(request, demande):
redo = "redo" in request.POST
manual = "manual" in request.POST
if not manual:
_traitement_attributions(request, demande)
demande.traitee = True
demande.traitee_par = request.user
demande.processed = timezone.now()
demande.save()
return render(
request,
"petitscours/traitement_demande_success.html",
{"demande": demande, "redo": redo},
)
def _traitement_attributions(request, demande):
proposals = {} proposals = {}
proposed_for = {} proposed_for = {}
unsatisfied = [] unsatisfied = []
extra = request.POST["extra"].strip() extra = request.POST["extra"].strip()
redo = "redo" in request.POST
attribdata = request.POST["attribdata"] attribdata = request.POST["attribdata"]
attribdata = dict(json.loads(attribdata)) attribdata = dict(json.loads(attribdata))
for matiere in demande.matieres.all(): for matiere in demande.matieres.all():
@ -253,15 +269,6 @@ def _traitement_post(request, demande):
user=user, matiere=matiere, demande=demande, rank=rank + 1 user=user, matiere=matiere, demande=demande, rank=rank + 1
) )
attrib.save() attrib.save()
demande.traitee = True
demande.traitee_par = request.user
demande.processed = timezone.now()
demande.save()
return render(
request,
"petitscours/traitement_demande_success.html",
{"demande": demande, "redo": redo},
)
@login_required @login_required