Minor update and optimisation

This commit is contained in:
Gregory Trullemans 2024-03-02 18:13:02 +01:00
parent 2276f35b4a
commit 571cf9da4a
5 changed files with 103 additions and 11 deletions

View File

@ -523,7 +523,10 @@ class Passe(Markdownizable):
def __str__(self):
if self.label:
return f"{self.label} ({self.number_of_skill} | {self.difficulty})"
if self.regexp:
return f"{self.label} {self.regexp} ({self.number_of_skill} | {self.difficulty})"
else:
return f"{self.label} ({self.number_of_skill} | {self.difficulty})"
else:
return f"- ({self.number_of_skill} | {self.difficulty})"

View File

@ -12,7 +12,7 @@
<table class="table table-striped tablesorter" id="trainingprogram_table">
<thead>
<tr>
<th colspan="4" class="text-center">{{ date|date:"l d F Y" }}</th>
<th colspan="5" class="text-center">{{ date|date:"l j F Y" }}</th>
</tr>
</thead>
<tbody>
@ -20,8 +20,22 @@
<tr role="row" class="{% cycle 'odd' 'even' %}">
<td>{{ trainingprogram.rank }}</td>
<td>{{ trainingprogram.passe.label }} {{ trainingprogram.passe.repetition }}</td>
<td class="text-center"><b>{{ trainingprogram.passe.number_of_skill}}</b></td>
<td class="text-center">{{ trainingprogram.passe.number_of_skill}}</td>
<td class="text-center">{{ trainingprogram.passe.difficulty }}</td>
{% if request.user|has_group:"trainer" %}
<td class="text-right p-2">
<a href="#" class="up">
<button type="submit" value="" class="btn btn-icon btn-warning mr-2">
<i class="fas fa-chevron-up"></i>
</button>
</a>
<a href="#" class="down">
<button type="submit" value="add" class="btn btn-icon btn-warning mr-2">
<i class="fas fa-chevron-down"></i>
</button>
</a>
</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
@ -29,6 +43,9 @@
<td colspan="2" class="text-right"><b>TOTAL</b></td>
<td class="text-center"><b>{{ number_of_skill }}</b></td>
<td class="text-center"><b>{{ difficulty }}</b></td>
{% if request.user|has_group:"trainer" %}
<td></td>
{% endif %}
</tr>
</table>
{% endif %}
@ -36,4 +53,39 @@
</div>
</div>
</div>
{% endblock %}
{% block footerscript %}
<script type="text/javascript">
$(document).ready(function(){
$(".up,.down").click(function(){
var row = $(this).parents("tr:first");
if ($(this).is(".up")) {
$.ajax({
url: "{% url 'switch_trainingprogram_line' %}",
method: "POST",
data: {
tp1: 5,
tp2: 6,
csrfmiddlewaretoken: '{{ csrf_token }}'
},
}).done(function() {
row.insertBefore(row.prev());
});
} else {
$.ajax({
url: "{% url 'switch_trainingprogram_line' %}",
method: "POST",
data: {
tp1: 6,
tp2: 5,
csrfmiddlewaretoken: '{{ csrf_token }}'
},
}).done(function() {
row.insertAfter(row.next());
});
}
});
});
</script>
{% endblock %}

View File

@ -107,4 +107,9 @@ urlpatterns = [
views.trainingprogram_details,
name="trainingprogram_details",
),
path(
r"trainingprogram/switch_trainingprogram_line/",
views.switch_trainingprogram_line,
name="switch_trainingprogram_line",
),
]

View File

@ -590,3 +590,38 @@ def trainingprogram_details(request, date=None, gymnast_id=None):
"trainingprogram_list": trainingprogram_list,
}
return render(request, "trainingprograms/details.html", context)
@require_http_methods(["POST"])
def switch_trainingprogram_line(request):
"""
Recoit dans request deux identifiants de trainingprogram qu'il faut échanger () :
- tp1 (int) identifiant d'une instance de TraiingProgram
- tp2 (int) identifiant d'une instance de TraiingProgram
J'utilise `32767` comme valeur intermédiaire pour le `rank` car c'est la limite supérieure d'un
PositiveSmallIntegerField.
"""
try:
target_trainingprogram_id = request.POST.get("tp1", None)
source_trainingprogram_id = request.POST.get("tp2", None)
target_trainingprogram = get_object_or_404(
TrainingProgram, pk=target_trainingprogram_id
)
source_trainingprogram = get_object_or_404(
TrainingProgram, pk=source_trainingprogram_id
)
saved_source_rank = source_trainingprogram.rank
saved_target_rank = target_trainingprogram.rank
source_trainingprogram.rank = 32767
source_trainingprogram.save()
target_trainingprogram.rank = saved_source_rank
target_trainingprogram.save()
source_trainingprogram.rank = saved_target_rank
source_trainingprogram.save()
except Exception:
return HttpResponse(409)
return HttpResponse(200)

View File

@ -3,7 +3,7 @@
<div class="row justify-content-center ml-1">
<div class="col-md-6">
<div class="card">
<div class="card mb-3">
<div class="card-header">
<h4>Intensity statistics</h4>
</div>
@ -35,7 +35,7 @@
</div>
<div class="col-md-6 pl-1">
<div class="card">
<div class="card mb-3">
<div class="card-header">
<h4>Chronos</h4>
</div>
@ -75,7 +75,7 @@
</div>
</div>
</div>
<div class="row justify-content-center ml-1">
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card">
<div class="card-header">
@ -84,15 +84,12 @@
<div class="card-body">
{% if date_list %}
{% for date in date_list %}
<a href="{% url 'trainingprogram_details' date gymnast_id %}">{{ date|date:"l d F Y" }}</a>
<a href="{% url 'trainingprogram_details' date gymnast_id %}">{{ date|date:"l j F Y" }}</a>
{% endfor %}
{% else %}
Pas de training planifié.
<p>Pas de training planifié.</p>
{% endif %}
</div>
<div class="card-footer text-right text-muted pt-0">
</div>
</div>
</div>
</div>