diff --git a/jarvis/objective/forms.py b/jarvis/objective/forms.py index baffdf8..0e26731 100644 --- a/jarvis/objective/forms.py +++ b/jarvis/objective/forms.py @@ -1,6 +1,6 @@ from django import forms -from .models import Skill, Routine, RoutineSkill +from .models import Skill, Routine, RoutineSkill, Passe class SkillForm(forms.ModelForm): @@ -64,3 +64,48 @@ class CombinationSkillForm(forms.ModelForm): "skill": forms.HiddenInput(), "rank": forms.NumberInput(), } + + +class PasseForm(forms.ModelForm): + class Meta: + model = Passe + fields = ("label", "educative", "repetition", "regexp", "informations") + widgets = { + "label": forms.TextInput( + attrs={ + "class": "form-control", + "placeholder": "Label (not mandatory)", + "maxlength": 30, + } + ), + "repetition": forms.NumberInput( + attrs={ + "class": "form-control", + "placeholder": "x", + "min": "0", + "max": "1000", + "step": "1", + } + ), + "regexp": forms.TextInput( + attrs={"class": "form-control", "placeholder": "[2-8]"} + ), + "informations": forms.Textarea( + attrs={ + "class": "form-control", + "placeholder": "Informations about the passe…", # pylint: disable=line-too-long + } + ), + "educative": forms.HiddenInput(), + } + + educative_related = forms.CharField( + required=False, + widget=forms.TextInput( + attrs={ + "class": "form-control", + "placeholder": "Searching educative", + "data-ref": "#id_educative", + } + ), + ) diff --git a/jarvis/objective/migrations/0017_passe.py b/jarvis/objective/migrations/0017_passe.py index d64685b..1b0ef98 100644 --- a/jarvis/objective/migrations/0017_passe.py +++ b/jarvis/objective/migrations/0017_passe.py @@ -1,6 +1,7 @@ -# Generated by Django 4.2 on 2024-02-25 07:33 +# Generated by Django 4.2 on 2024-02-25 18:38 from django.db import migrations, models +import django.db.models.deletion class Migration(migrations.Migration): @@ -22,14 +23,30 @@ class Migration(migrations.Migration): verbose_name="ID", ), ), - ("label", models.CharField(blank=True, max_length=25, null=True)), - ("repetition", models.PositiveSmallIntegerField()), + ( + "informations", + models.TextField( + blank=True, + help_text="Only MarkDown is authorized", + null=True, + verbose_name="Comments", + ), + ), + ("label", models.CharField(blank=True, max_length=30, null=True)), + ("repetition", models.PositiveSmallIntegerField(default=1)), + ("regexp", models.CharField(blank=True, max_length=50, null=True)), + ("number_of_skill", models.PositiveSmallIntegerField()), + ("difficulty", models.DecimalField(decimal_places=1, max_digits=4)), ( "educative", - models.ManyToManyField( - related_name="passes", to="objective.educative" + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + to="objective.educative", ), ), ], + options={ + "abstract": False, + }, ), ] diff --git a/jarvis/objective/migrations/0018_passe_regexp_remove_passe_educative_and_more.py b/jarvis/objective/migrations/0018_passe_regexp_remove_passe_educative_and_more.py deleted file mode 100644 index 72f857e..0000000 --- a/jarvis/objective/migrations/0018_passe_regexp_remove_passe_educative_and_more.py +++ /dev/null @@ -1,38 +0,0 @@ -# Generated by Django 4.2 on 2024-02-25 08:54 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ("objective", "0017_passe"), - ] - - operations = [ - migrations.AddField( - model_name="passe", - name="regexp", - field=models.CharField(blank=True, max_length=50, null=True), - ), - migrations.RemoveField( - model_name="passe", - name="educative", - ), - migrations.AlterField( - model_name="passe", - name="label", - field=models.CharField(blank=True, max_length=30, null=True), - ), - migrations.AddField( - model_name="passe", - name="educative", - field=models.ForeignKey( - default=None, - on_delete=django.db.models.deletion.CASCADE, - to="objective.educative", - ), - preserve_default=False, - ), - ] diff --git a/jarvis/objective/models.py b/jarvis/objective/models.py index e205acc..e83ac2c 100644 --- a/jarvis/objective/models.py +++ b/jarvis/objective/models.py @@ -458,13 +458,59 @@ class RoutineSkill(models.Model): return f"{self.rank} - {self.routine.short_label} : {self.skill.short_label}" -class Passe(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) educative = models.ForeignKey(Educative, on_delete=models.CASCADE) - repetition = models.PositiveSmallIntegerField() + repetition = models.PositiveSmallIntegerField(default=1) regexp = models.CharField(max_length=50, null=True, blank=True) + number_of_skill = models.PositiveSmallIntegerField() + difficulty = models.DecimalField(max_digits=4, decimal_places=1) + + def save(self, *args, **kwargs): + """Sauve les informations de la personne et initialise les champs nettoyés.""" + is_skill = False + try: + educative = Routine.objects.get(pk=self.educative) + except Routine.DoesNotExist: + educative = Skill.objects.get(pk=self.educative) + is_skill = True + + if is_skill: + self.number_of_skill = self.repetition + self.difficulty = educative.difficulty * self.repetition + else: + if self.regexp is not None: + regexp = self.regexp.replace("[", "").replace("]", "") + position = regexp.find("-") + + start = regexp[:position] + if start == "": + start = 0 + else: + start = int(start) + + end = regexp[position + 1 :] + if end == "": + end = educative.jumps.all().count() + else: + end = int(end) + + self.number_of_skill = (end - (start - 1)) * self.repetition + list_of_skill = educative.skill_links.filter( + rank__gte=start, rank__lte=end + ) + # .aggregate(total=Sum("value")) + self.difficulty = 0 + for routine_skill in list_of_skill: + self.difficulty += routine_skill.skill.difficulty + self.difficulty *= self.repetition + + else: + self.number_of_skill = educative.jumps.all().count() * self.repetition + self.difficulty = educative.difficulty * self.repetition + super().save(*args, **kwargs) def __str__(self): if self.label: diff --git a/jarvis/objective/templates/combinations/create.html b/jarvis/objective/templates/combinations/create.html index cd1c475..6c584b5 100644 --- a/jarvis/objective/templates/combinations/create.html +++ b/jarvis/objective/templates/combinations/create.html @@ -14,30 +14,30 @@ {{ hidden }} {% endfor %}
- | {{ link.skill.notation }} | -{{ link.skill.short_label }} | -{% if link.skill.difficulty != 0.0 %}{{ link.skill.difficulty }}{% endif %} | -
- | {{ combination.difficulty }} | -
No skill defined for this combination.
- {% endif %} -- {% endif %} - | Long Label | -Short Label | -Competitive ? | -- | - | Diff. | -Level | -Rank | -
---|---|---|---|---|---|---|---|---|
- - - - | - {% endif %} -{{ routine.long_label }} | -{{ routine.short_label }} | -- {% if routine.is_competitive %} - {% else %} - {% endif %} - | -{{ routine.age_girl_masterised }} | -{{ routine.age_boy_masterised }} | -{{ routine.difficulty }} | -{{ routine.level }} | -{{ routine.rank }} | -
label | +educative | +repetition | +regexp | +
---|---|---|---|
{{ passe.label }} | +{{ passe.educative }} | +{{ passe.repetition }} | +{{ passe.regexp }} | +
There are no {{ title|lower }} corresponding to your criterias.
+There are no passe corresponding to your criterias.
{% endif %}--DATE-- | + + {% for trainingprogram in trainingprogram_list %} +||
{{ trainingprogram.passe.label }} {{ trainingprogram.passe.repetition }} | +{{ trainingprogram.passe.number_of_skill}} | +{{ trainingprogram.passe.difficulty }} | +