Un paquet d'améliorations django, JS, …
This commit is contained in:
parent
9b27587a4d
commit
a87d4f41c8
|
@ -0,0 +1,33 @@
|
|||
# Generated by Django 4.2 on 2024-03-03 10:45
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("objective", "0018_alter_trainingprogram_options_and_more"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name="passe",
|
||||
options={"ordering": ["label"]},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="trainingprogram",
|
||||
name="informations",
|
||||
field=models.TextField(
|
||||
blank=True,
|
||||
help_text="Only MarkDown is authorized",
|
||||
null=True,
|
||||
verbose_name="Comments",
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="passe",
|
||||
name="label",
|
||||
field=models.CharField(default="-", max_length=30),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
|
@ -465,7 +465,10 @@ class RoutineSkill(models.Model):
|
|||
class Passe(Markdownizable):
|
||||
"""Classe représentant les passages (à faire pendant un entraînement)."""
|
||||
|
||||
label = models.CharField(max_length=30, null=True, blank=True)
|
||||
class Meta:
|
||||
ordering = ["label"]
|
||||
|
||||
label = models.CharField(max_length=30)
|
||||
educatives = models.ManyToManyField(Educative)
|
||||
regexp = models.CharField(max_length=50, null=True, blank=True)
|
||||
number_of_skill = models.PositiveSmallIntegerField(default=0)
|
||||
|
@ -522,13 +525,10 @@ class Passe(Markdownizable):
|
|||
super().save(*args, **kwargs)
|
||||
|
||||
def __str__(self):
|
||||
if self.label:
|
||||
return f"{self.label} ({self.number_of_skill} | {self.difficulty})"
|
||||
else:
|
||||
return f"- ({self.number_of_skill} | {self.difficulty})"
|
||||
|
||||
|
||||
class TrainingProgram(Seasonisable):
|
||||
class TrainingProgram(Seasonisable, Markdownizable):
|
||||
"""Classe représentant un entraînement (ensemble de passage)."""
|
||||
|
||||
class Meta:
|
||||
|
|
|
@ -1,21 +1,89 @@
|
|||
{% extends "base.html" %}
|
||||
{% load has_group %}
|
||||
|
||||
{% block page_title %}{{ combination.short_label }}{% endblock %}
|
||||
{% block page_title %}Passe details{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-12 col-sm-12 col-md-8 col-lg-8 col-xl-6">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<b><u>Label :</b></u> {{ passe.label }}<br />
|
||||
<b><u>Content :</b></u> {% for educative in passe.educative.all %}{{ educative }}{% if not forloop.last %} & {% endif %}{% endfor %}<br />
|
||||
<b><u>Répétition :</b></u> {{ passe.repetition }}<br />
|
||||
{% if passe.regexp %}<b><u>RegExp :</b></u> {{ passe.regexp }}<br />{% endif %}
|
||||
<br />
|
||||
<a href="#">{{ passe.label }}{% if passe.regexp %}{{ passe.regexp }}{% endif %}</a> {{ passe.repetition }}<br /><br />
|
||||
{{ number_of_skill }} - {{ difficulty }}
|
||||
|
||||
<div class="card-header">
|
||||
<h4 class="mb-0">Passe details</h3>
|
||||
<h5 class="card-category mb-0">{{ passe.label }}{% if passe.regexp %}{{ passe.regexp }}{% endif %}</a> {{ passe.repetition }}</h4>
|
||||
</div>
|
||||
|
||||
<div class="card-body">
|
||||
<form class="form-horizontal" id="formulaire" name="formulaire">
|
||||
|
||||
<div class="form-group row mb-0">
|
||||
<label for="id_label" class="col-4 col-sm-6 col-md-5 col-lg-4 col-xl-3 col-form-label">Label</label>
|
||||
<div class="col-8 col-sm-6 col-md-7 col-lg-8 col-xl-9 pt-2">
|
||||
{{ passe.label }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row mb-0">
|
||||
<label for="id_educative" class="col-4 col-sm-6 col-md-5 col-lg-4 col-xl-3 col-form-label">Content</label>
|
||||
<div class="col-8 col-sm-8 col-md-6 col-lg-6 col-xl-6 pt-2">
|
||||
{% if passe.educatives.all.count > 1%}
|
||||
<ul class="mb-0 ml-4 pl-0">
|
||||
{% for educative in passe.educatives.all %}
|
||||
<li><a href="{% url 'educative_details' educative.id %}">{{ educative }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
{{ passe.educatives }}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if passe.regexp %}
|
||||
<div class="form-group row mb-0">
|
||||
<label for="id_regexp" class="col-4 col-sm-6 col-md-5 col-lg-4 col-xl-3 col-form-label">Regexp<span class="text-danger"><b>*</b></span></label>
|
||||
<div class="col-4 col-sm-4 col-md-4 col-lg-4 col-xl-3 pt-2">
|
||||
{{ passe.regexp }}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="form-group row mb-0">
|
||||
<label for="id_regexp" class="col-4 col-sm-6 col-md-5 col-lg-4 col-xl-3 col-form-label">Number of Skill</label>
|
||||
<div class="col-4 col-sm-4 col-md-4 col-lg-4 col-xl-3 pt-2">
|
||||
{{ number_of_skill }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row mb-0">
|
||||
<label for="id_regexp" class="col-4 col-sm-6 col-md-5 col-lg-4 col-xl-3 col-form-label">Difficulty</label>
|
||||
<div class="col-4 col-sm-4 col-md-4 col-lg-4 col-xl-3 pt-2">
|
||||
{{ difficulty }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if information %}
|
||||
<div class="form-group row mb-0">
|
||||
<label for="id_informations" class="col-4 col-sm-6 col-md-5 col-lg-4 col-xl-3 col-form-label">Informations</label>
|
||||
<div class="col-8 col-sm-9 col-md-9 col-lg-9 col-xl-9 {% if form.id_information.errors %}has-danger{% endif %}">
|
||||
{{ informations }}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="card-footer row pt-0">
|
||||
<div class="col-6">
|
||||
<a href="#">
|
||||
<button type="submit" value="add" class="btn btn-icon btn-warning ">
|
||||
<i class="tim-icons icon-double-left"></i>
|
||||
</button>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% extends "base.html" %}
|
||||
{% load has_group %}
|
||||
|
||||
{% block page_title %}{{ combination.short_label }}{% endblock %}
|
||||
{% block page_title %}Training Program{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row justify-content-center">
|
||||
|
@ -18,18 +18,19 @@
|
|||
<tbody>
|
||||
{% for trainingprogram in trainingprogram_list %}
|
||||
<tr role="row" class="{% cycle 'odd' 'even' %}">
|
||||
<td>{{ trainingprogram.rank }}</td>
|
||||
<td class="text-center">{{ trainingprogram.passe.label }}{% if trainingprogram.repetition != 1 %} {{ trainingprogram.repetition }}{% endif %}</td>
|
||||
<td><b>{{ trainingprogram.rank }}</b></td>
|
||||
<td class="text-center"><a href="{% url 'passe_details' trainingprogram.passe.id %}">{{ trainingprogram.passe.label }}</a>{% if trainingprogram.repetition != 1 %} {{ trainingprogram.repetition }}{% endif %}</td>
|
||||
<td class="text-center">{{ trainingprogram.number_of_skill}}</td>
|
||||
<td class="text-center">{{ trainingprogram.difficulty }}</td>
|
||||
{% if request.user|has_group:"trainer" %}
|
||||
<td class="text-right p-2">
|
||||
<a href="#" class="up">
|
||||
<td class="text-center p-2">
|
||||
<a href="#" class="up" data-tp_id="{{ trainingprogram.id }}" data-rank="{{ trainingprogram.rank }}">
|
||||
<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">
|
||||
|
||||
<a href="#" class="down" data-tp_id="{{ trainingprogram.id }}" data-rank="{{ trainingprogram.rank }}">
|
||||
<button type="submit" value="add" class="btn btn-icon btn-warning mr-2">
|
||||
<i class="fas fa-chevron-down"></i>
|
||||
</button>
|
||||
|
@ -60,16 +61,26 @@
|
|||
$(document).ready(function(){
|
||||
$(".up,.down").click(function(){
|
||||
var row = $(this).parents("tr:first");
|
||||
var first_td = row.find("td:first");
|
||||
saved_rank = first_td.text(); // jusque là, ca marche !
|
||||
// alert("Rank : " + saved_rank);
|
||||
|
||||
if ($(this).is(".up")) {
|
||||
$.ajax({
|
||||
url: "{% url 'switch_trainingprogram_line' %}",
|
||||
method: "POST",
|
||||
data: {
|
||||
tp1: 5,
|
||||
tp2: 6,
|
||||
tpid: $(this).data('tp_id'),
|
||||
direction: 0,
|
||||
csrfmiddlewaretoken: '{{ csrf_token }}'
|
||||
},
|
||||
}).done(function() {
|
||||
var previous_td = row.prev().find('td:first');
|
||||
saved_previous_rank = previous_td.text();
|
||||
|
||||
first_td.html("<b>" + String(saved_previous_rank) + "</b>");
|
||||
previous_td.html("<b>" + String(saved_rank) + "</b>");
|
||||
|
||||
row.insertBefore(row.prev());
|
||||
});
|
||||
} else {
|
||||
|
@ -77,11 +88,17 @@ $(document).ready(function(){
|
|||
url: "{% url 'switch_trainingprogram_line' %}",
|
||||
method: "POST",
|
||||
data: {
|
||||
tp1: 6,
|
||||
tp2: 5,
|
||||
tpid: $(this).data('tp_id'),
|
||||
direction: 1,
|
||||
csrfmiddlewaretoken: '{{ csrf_token }}'
|
||||
},
|
||||
}).done(function() {
|
||||
var next = row.next().find('td:first');
|
||||
saved_next_rank = previous_td.text();
|
||||
|
||||
first_td.html("<b>" + String(saved_next_rank) + "</b>");
|
||||
next.html("<b>" + String(saved_rank) + "</b>");
|
||||
|
||||
row.insertAfter(row.next());
|
||||
});
|
||||
}
|
||||
|
|
|
@ -7,6 +7,11 @@ urlpatterns = [
|
|||
#
|
||||
#
|
||||
path(r"educative/lookup/", views.educative_lookup, name="educative_lookup"),
|
||||
path(
|
||||
r"educative/details/<int:educative_id>",
|
||||
views.educative_details,
|
||||
name="educative_details",
|
||||
),
|
||||
#
|
||||
# SKILLS
|
||||
#
|
||||
|
|
|
@ -49,6 +49,17 @@ def educative_lookup(request):
|
|||
return JsonResponse(results, safe=False)
|
||||
|
||||
|
||||
@login_required
|
||||
@require_http_methods(["GET"])
|
||||
def educative_details(request, educative_id):
|
||||
"""Renvoie les détails d'un educatif suivant que ce soit une combination ou un skill"""
|
||||
try:
|
||||
Routine.objects.get(pk=educative_id)
|
||||
return combination_details(request, educative_id)
|
||||
except Routine.DoesNotExist:
|
||||
return skill_details(request, educative_id)
|
||||
|
||||
|
||||
@login_required
|
||||
@require_http_methods(["POST"])
|
||||
def skill_lookup(request):
|
||||
|
@ -596,21 +607,31 @@ def trainingprogram_details(request, date=None, gymnast_id=None):
|
|||
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
|
||||
- tp_id (int) identifiant d'une instance de TraiingProgram
|
||||
- direction (str) la direction du changement (0: haut, 1: bas)
|
||||
|
||||
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_id = request.POST.get("tpid", None)
|
||||
direction = int(request.POST.get("direction", 0))
|
||||
|
||||
target_trainingprogram = get_object_or_404(
|
||||
TrainingProgram, pk=target_trainingprogram_id
|
||||
)
|
||||
source_trainingprogram = get_object_or_404(
|
||||
TrainingProgram, pk=source_trainingprogram_id
|
||||
|
||||
if direction == 0:
|
||||
source_trainingprogram = (
|
||||
TrainingProgram.objects.filter(rank__lt=target_trainingprogram.rank)
|
||||
.order_by("-id")
|
||||
.first()
|
||||
)
|
||||
else:
|
||||
source_trainingprogram = (
|
||||
TrainingProgram.objects.filter(rank__gt=target_trainingprogram.rank)
|
||||
.order_by("id")
|
||||
.first()
|
||||
)
|
||||
|
||||
saved_source_rank = source_trainingprogram.rank
|
||||
|
@ -621,7 +642,7 @@ def switch_trainingprogram_line(request):
|
|||
target_trainingprogram.save()
|
||||
source_trainingprogram.rank = saved_target_rank
|
||||
source_trainingprogram.save()
|
||||
except Exception:
|
||||
return HttpResponse(409)
|
||||
|
||||
return HttpResponse(200)
|
||||
except Exception:
|
||||
return HttpResponse(409)
|
||||
|
|
Loading…
Reference in New Issue