[WIP] Minor updates
This commit is contained in:
parent
42467ac19c
commit
4597b859f5
|
@ -455,7 +455,7 @@ class RoutineSkill(models.Model):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ("rank",)
|
ordering = ["routine", "rank"]
|
||||||
unique_together = ["routine", "rank"]
|
unique_together = ["routine", "rank"]
|
||||||
|
|
||||||
routine = models.ForeignKey(
|
routine = models.ForeignKey(
|
||||||
|
@ -582,7 +582,7 @@ class GymnastTrainingRound(Markdownizable):
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = "Gymnast Training Round"
|
verbose_name = "Gymnast Training Round"
|
||||||
verbose_name_plural = "Gymnast Training Rounds"
|
verbose_name_plural = "Gymnast Training Rounds"
|
||||||
ordering = ("rank",)
|
ordering = ["gymnast_training", "rank"]
|
||||||
unique_together = ["gymnast_training", "rank"]
|
unique_together = ["gymnast_training", "rank"]
|
||||||
|
|
||||||
gymnast_training = models.ForeignKey(
|
gymnast_training = models.ForeignKey(
|
||||||
|
|
|
@ -11,41 +11,50 @@
|
||||||
<h4 class="">Compose Training : {{ gymnast_training.gymnast }} - {{ gymnast_training.date|date:"l j F Y" }}</h4>
|
<h4 class="">Compose Training : {{ gymnast_training.gymnast }} - {{ gymnast_training.date|date:"l j F Y" }}</h4>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<ol>
|
<ul class="no-bullets" id="ul-rounds-list"><li>
|
||||||
{% for training_round in training_round_list %}
|
<div class="form-group row pb-0 mb-0">
|
||||||
|
<label class="col-2 col-form-label pb-0 text-center">Rank</label>
|
||||||
|
<label class="col-7 col-form-label pb-0">Label</label>
|
||||||
|
<label class="col-3 col-form-label pb-0">Repetition</label>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
{% for gtr in gtr_list %}
|
||||||
<li>
|
<li>
|
||||||
<div class="form-group row pb-0 mb-0">
|
<div class="form-group row pb-0 mb-0">
|
||||||
<label class="col-1 col-form-label pt-2 pb-0 text-right"> </label>
|
<label class="col-2 col-form-label pt-2 pb-0 text-center">{{ gtr.rank }}</label>
|
||||||
<div class="col-11 pt-2 text-danger">
|
<div class="col-7 pt-2 text-danger">
|
||||||
{{ training_round.label }}
|
{{ gtr.training_round.label }}
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</li>
|
<div class="col-3 pt-2 text-danger">
|
||||||
{% endfor %}
|
{{ gtr.repetition }}
|
||||||
<li>
|
|
||||||
<div class="form-group row pb-0 mb-0">
|
|
||||||
<label class="col-1 col-form-label text-right mb-0"> </label>
|
|
||||||
<div class="col-7 mb-0">
|
|
||||||
<input type="hidden" name="traininground_id" id="id_traininground_id" value="">
|
|
||||||
<input type="text" name="traininground" placeholder="Training round" class="form-control selectpicker" id="id_traininground">
|
|
||||||
</div>
|
|
||||||
<div class="col-3 mb-0">
|
|
||||||
<select type="text" name="repetition" placeholder="Repetition" class="form-control selectpicker" id="id_repetition">
|
|
||||||
<option>-----</option>
|
|
||||||
<option>1</option>
|
|
||||||
<option>2</option>
|
|
||||||
<option>3</option>
|
|
||||||
<option>4</option>
|
|
||||||
<option>5</option>
|
|
||||||
<option>6</option>
|
|
||||||
<option>7</option>
|
|
||||||
<option>8</option>
|
|
||||||
<option>9</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</li>
|
</li>
|
||||||
</ol>
|
{% endfor %}
|
||||||
|
<li>
|
||||||
|
<div class="form-group row pb-0 mb-0">
|
||||||
|
<label class="col-2 col-form-label text-right mb-0 text-center" id="label_rank">{{ rank }}</label>
|
||||||
|
<div class="col-7 mb-0">
|
||||||
|
<input type="hidden" name="traininground_id" id="id_traininground_id" value="">
|
||||||
|
<input type="text" name="traininground" placeholder="Training round" class="form-control selectpicker" id="id_traininground">
|
||||||
|
</div>
|
||||||
|
<div class="col-3 mb-0">
|
||||||
|
<select type="text" name="repetition" placeholder="Repetition" class="form-control selectpicker" id="id_repetition">
|
||||||
|
<option>-----</option>
|
||||||
|
<option>1</option>
|
||||||
|
<option>2</option>
|
||||||
|
<option>3</option>
|
||||||
|
<option>4</option>
|
||||||
|
<option>5</option>
|
||||||
|
<option>6</option>
|
||||||
|
<option>7</option>
|
||||||
|
<option>8</option>
|
||||||
|
<option>9</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-footer pt-0">
|
<div class="card-footer pt-0">
|
||||||
<a href="{% url 'gymnast_training_details' gymnast_training.id %}">
|
<a href="{% url 'gymnast_training_details' gymnast_training.id %}">
|
||||||
|
@ -62,12 +71,14 @@
|
||||||
{% block footerscript %}
|
{% block footerscript %}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
const csrf_token = "{{ csrf_token|escapejs }}";
|
const csrf_token = "{{ csrf_token|escapejs }}";
|
||||||
const traininground_lookup = "{% url 'traininground_lookup' %}";
|
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
var repetition = 0;
|
||||||
|
var round_label = "";
|
||||||
var rank = {{ rank }};
|
var rank = {{ rank }};
|
||||||
|
$('#id_traininground').focus();
|
||||||
|
|
||||||
function insert_round()
|
function insert_round(repetition)
|
||||||
{
|
{
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "{% url 'link_round_to_training' %}",
|
url: "{% url 'link_round_to_training' %}",
|
||||||
|
@ -80,25 +91,22 @@
|
||||||
csrfmiddlewaretoken: '{{ csrf_token }}'
|
csrfmiddlewaretoken: '{{ csrf_token }}'
|
||||||
},
|
},
|
||||||
}).done(function() {
|
}).done(function() {
|
||||||
// landing_position_id = ui.item.landingid;
|
insert_selected_round(round_label, repetition);
|
||||||
insert_selected_round(ui.item.notation);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#id_traininground').focus();
|
|
||||||
|
|
||||||
$('#id_repetition').on("change", function(){
|
$('#id_repetition').on("change", function(){
|
||||||
if($("select option:selected").val() != "-----") {
|
if($("select option:selected").val() != "-----")
|
||||||
// alert($('#id_traininground').val());
|
insert_round($("select option:selected").val());
|
||||||
insert_round();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function insert_selected_round(skill_label="Test")
|
function insert_selected_round(round_label="Test", repetition=1)
|
||||||
{
|
{
|
||||||
$('#minusButton').remove();
|
// $('#minusButton').remove();
|
||||||
$('ol li:last-child').before('<li><div class="form-group row pb-0 mb-0"><label class="col-1 col-sm-1 col-md-1 col-lg-1 col-xl-1 col-form-label text-right mb-0"> </label><div class="col-3 col-sm-3 col-md-3 col-lg-3 col-xl-3 pt-2 mb-0">' + skill_label + '</div><div class="col-1 col-sm-1 col-md-1 col-lg-1 col-xl-1"><button type="button" class="btn btn-warning btn-sm" id="minusButton">-</button></div></div></li>');
|
$('#ul-rounds-list li:last-child').before('<div class="form-group row pb-0 mb-0"><label class="col-2 col-form-label pt-2 pb-0 text-center">' + rank + '</label><div class="col-7 pt-2 text-danger">' + round_label + '</div><div class="col-3 pt-2 text-danger">' + repetition + '</div></div>');
|
||||||
$('#id_skill').val('').focus();
|
rank += 1;
|
||||||
|
$('#label_rank').html(rank);
|
||||||
|
$('#id_traininground').val('').focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
// $('body').on('click', '#minusButton', function(event){
|
// $('body').on('click', '#minusButton', function(event){
|
||||||
|
@ -118,7 +126,7 @@
|
||||||
$('#id_traininground').autocomplete({
|
$('#id_traininground').autocomplete({
|
||||||
source: function(request, response) {
|
source: function(request, response) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: traininground_lookup,
|
url: "{% url 'traininground_lookup' %}",
|
||||||
method: "POST",
|
method: "POST",
|
||||||
data: {
|
data: {
|
||||||
pattern: request.term,
|
pattern: request.term,
|
||||||
|
@ -147,8 +155,8 @@
|
||||||
},
|
},
|
||||||
minLength: 2,
|
minLength: 2,
|
||||||
select: function (event, ui) {
|
select: function (event, ui) {
|
||||||
$('#id_traininground_id').val(ui.item.trainingroun_id)
|
$('#id_traininground_id').val(ui.item.trainingroun_id);
|
||||||
rank += 1;
|
round_label = ui.item.label;
|
||||||
$('#id_repetition').focus();
|
$('#id_repetition').focus();
|
||||||
},
|
},
|
||||||
{% if request.session.template == 0 %}
|
{% if request.session.template == 0 %}
|
||||||
|
|
|
@ -485,12 +485,8 @@ def link_skill_to_combination(request):
|
||||||
form = CombinationSkillForm(data)
|
form = CombinationSkillForm(data)
|
||||||
|
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
link, created = RoutineSkill.objects.get_or_create(
|
form.save()
|
||||||
routine=form.cleaned_data["routine"],
|
return HttpResponse(200)
|
||||||
skill=form.cleaned_data["skill"],
|
|
||||||
rank=form.cleaned_data["rank"],
|
|
||||||
)
|
|
||||||
return HttpResponse(200, (link, created))
|
|
||||||
|
|
||||||
return HttpResponse(406)
|
return HttpResponse(406)
|
||||||
|
|
||||||
|
@ -598,7 +594,7 @@ def traininground_create_or_update(request, traininground_id=None):
|
||||||
return HttpResponseRedirect(
|
return HttpResponseRedirect(
|
||||||
reverse("traininground_details", args=(traininground.pk,))
|
reverse("traininground_details", args=(traininground.pk,))
|
||||||
)
|
)
|
||||||
# print(form.errors)
|
|
||||||
return render(request, "trainingrounds/create.html", {"form": form})
|
return render(request, "trainingrounds/create.html", {"form": form})
|
||||||
|
|
||||||
form = TrainingRoundForm(instance=traininground)
|
form = TrainingRoundForm(instance=traininground)
|
||||||
|
@ -612,7 +608,7 @@ def gymnast_training_details(request, gymnast_training_id):
|
||||||
"""Détails d'un entraînement."""
|
"""Détails d'un entraînement."""
|
||||||
|
|
||||||
gymnast_training = get_object_or_404(GymnastTraining, pk=gymnast_training_id)
|
gymnast_training = get_object_or_404(GymnastTraining, pk=gymnast_training_id)
|
||||||
training_rounds = gymnast_training.training_rounds.all()
|
training_rounds = gymnast_training.rounds_links.all()
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
"gymnast": gymnast_training.gymnast,
|
"gymnast": gymnast_training.gymnast,
|
||||||
|
@ -631,6 +627,8 @@ def switch_traininground(request):
|
||||||
|
|
||||||
J'utilise `32767` comme valeur intermédiaire pour le `rank` car c'est la limite supérieure d'un
|
J'utilise `32767` comme valeur intermédiaire pour le `rank` car c'est la limite supérieure d'un
|
||||||
PositiveSmallIntegerField.
|
PositiveSmallIntegerField.
|
||||||
|
|
||||||
|
TODO: ramener un rank d'un seul coup.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
target_trainingprogram_id = request.POST.get("tpid", None)
|
target_trainingprogram_id = request.POST.get("tpid", None)
|
||||||
|
@ -646,21 +644,33 @@ def switch_traininground(request):
|
||||||
.order_by("-id")
|
.order_by("-id")
|
||||||
.first()
|
.first()
|
||||||
)
|
)
|
||||||
|
new_rank = (target_trainingpround.rank - source_traininground.rank) - 1
|
||||||
|
is_switchable = (source_traininground.rank == new_rank)
|
||||||
else:
|
else:
|
||||||
source_traininground = (
|
source_traininground = (
|
||||||
GymnastTrainingRound.objects.filter(rank__gt=target_trainingpround.rank)
|
GymnastTrainingRound.objects.filter(rank__gt=target_trainingpround.rank)
|
||||||
.order_by("id")
|
.order_by("id")
|
||||||
.first()
|
.first()
|
||||||
)
|
)
|
||||||
|
new_rank = (source_traininground.rank - target_trainingpround.rank) - 1
|
||||||
|
is_switchable = (source_traininground.rank == new_rank)
|
||||||
|
|
||||||
saved_source_rank = source_traininground.rank
|
if is_switchable:
|
||||||
saved_target_rank = target_trainingpround.rank
|
saved_source_rank = source_traininground.rank
|
||||||
source_traininground.rank = 32767
|
saved_target_rank = target_trainingpround.rank
|
||||||
source_traininground.save()
|
source_traininground.rank = 32767
|
||||||
target_trainingpround.rank = saved_source_rank
|
source_traininground.save()
|
||||||
target_trainingpround.save()
|
target_trainingpround.rank = saved_source_rank
|
||||||
source_traininground.rank = saved_target_rank
|
target_trainingpround.save()
|
||||||
source_traininground.save()
|
source_traininground.rank = saved_target_rank
|
||||||
|
source_traininground.save()
|
||||||
|
else:
|
||||||
|
if direction == 0:
|
||||||
|
new_rank = source_traininground.rank + 1
|
||||||
|
else:
|
||||||
|
new_rank = source_traininground.rank - 1
|
||||||
|
target_trainingpround.rank = new_rank
|
||||||
|
target_trainingpround.save()
|
||||||
|
|
||||||
return HttpResponse(200)
|
return HttpResponse(200)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
@ -694,7 +704,7 @@ def gymnast_training_create_or_update(request, gymnasttraining_id=None, gymnast_
|
||||||
return HttpResponseRedirect(
|
return HttpResponseRedirect(
|
||||||
reverse("gymnast_training_details", args=(gymnasttraining.pk,))
|
reverse("gymnast_training_details", args=(gymnasttraining.pk,))
|
||||||
)
|
)
|
||||||
# print(form.errors)
|
|
||||||
return render(request, "gymnasttrainings/create.html", {"form": form})
|
return render(request, "gymnasttrainings/create.html", {"form": form})
|
||||||
|
|
||||||
form = GymnastTrainingForm(instance=gymnasttraining, initial=data)
|
form = GymnastTrainingForm(instance=gymnasttraining, initial=data)
|
||||||
|
@ -729,13 +739,17 @@ def gymnast_training_compose(request, gymnast_training_id):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
gymnast_training = get_object_or_404(GymnastTraining, pk=gymnast_training_id)
|
gymnast_training = get_object_or_404(GymnastTraining, pk=gymnast_training_id)
|
||||||
training_round_list = gymnast_training.trainingrounds.all()
|
gtr_list = gymnast_training.rounds_links.all()
|
||||||
|
rank = gtr_list.count()
|
||||||
|
if not rank:
|
||||||
|
print("rank vide")
|
||||||
|
rank = 1
|
||||||
|
print(rank)
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
"gymnast_training": gymnast_training,
|
"gymnast_training": gymnast_training,
|
||||||
"training_round_list": training_round_list,
|
"gtr_list": gtr_list,
|
||||||
"rank": training_round_list.count(),
|
"rank": rank,
|
||||||
# "skill_list": skill_list,
|
|
||||||
}
|
}
|
||||||
return render(request, "gymnasttrainings/compose.html", context)
|
return render(request, "gymnasttrainings/compose.html", context)
|
||||||
|
|
||||||
|
@ -750,7 +764,6 @@ def traininground_lookup(request):
|
||||||
trainingrounds = []
|
trainingrounds = []
|
||||||
pattern = request.POST.get("pattern", None)
|
pattern = request.POST.get("pattern", None)
|
||||||
|
|
||||||
# Ignore queries shorter than length 2
|
|
||||||
if pattern is not None and len(pattern) > 1:
|
if pattern is not None and len(pattern) > 1:
|
||||||
traininground_list = TrainingRound.objects.filter(label__icontains=pattern)
|
traininground_list = TrainingRound.objects.filter(label__icontains=pattern)
|
||||||
trainingrounds = [
|
trainingrounds = [
|
||||||
|
@ -776,23 +789,10 @@ def link_round_to_training(request):
|
||||||
"repetition": request.POST.get("repetition", 0),
|
"repetition": request.POST.get("repetition", 0),
|
||||||
"rank": request.POST.get("rank", 0),
|
"rank": request.POST.get("rank", 0),
|
||||||
}
|
}
|
||||||
print()
|
|
||||||
print()
|
|
||||||
print(data)
|
|
||||||
print()
|
|
||||||
print()
|
|
||||||
form = GymnastTrainingRoundForm(data)
|
form = GymnastTrainingRoundForm(data)
|
||||||
|
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
# print("Form valid.")
|
form.save()
|
||||||
link, created = GymnastTrainingRound.objects.get_or_create(
|
return HttpResponse(200)
|
||||||
gymnast_training=form.cleaned_data["gymnast_training"],
|
|
||||||
training_round=form.cleaned_data["training_round"],
|
|
||||||
repetition=form.cleaned_data["repetition"],
|
|
||||||
rank=form.cleaned_data["rank"],
|
|
||||||
)
|
|
||||||
print(created)
|
|
||||||
return HttpResponse(200, (link, created))
|
|
||||||
|
|
||||||
print("Form not valid.")
|
|
||||||
return HttpResponse(406)
|
return HttpResponse(406)
|
||||||
|
|
|
@ -143,4 +143,10 @@ textarea.form-control {
|
||||||
background-image: linear-gradient(to bottom left, #ec250d, #fd5d93, #ec250d);
|
background-image: linear-gradient(to bottom left, #ec250d, #fd5d93, #ec250d);
|
||||||
background-size: 210% 210%;
|
background-size: 210% 210%;
|
||||||
background-position: top right;
|
background-position: top right;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul.no-bullets {
|
||||||
|
list-style-type: none; /* Remove bullets */
|
||||||
|
padding: 0; /* Remove padding */
|
||||||
|
margin: 0; /* Remove margins */
|
||||||
}
|
}
|
Loading…
Reference in New Issue