Add field to Injury and add injury location

This commit is contained in:
Gregory Trullemans 2023-07-11 11:04:21 +02:00
parent d226109e28
commit c539539976
2 changed files with 70 additions and 11 deletions

View File

@ -183,7 +183,16 @@ class ScoreForm(forms.ModelForm):
class InjuryForm(forms.ModelForm):
class Meta:
model = Injury
fields = ("gymnast", "date", "nb_week_off", "informations")
fields = (
"gymnast",
"date",
"mechanism",
"location",
"body_side",
"nb_week_off",
"diagnosis",
"informations",
)
widgets = {
"date": forms.DateInput(
attrs={
@ -194,13 +203,22 @@ class InjuryForm(forms.ModelForm):
),
"gymnast": forms.HiddenInput(),
"skill": forms.HiddenInput(),
"mechanism": forms.Select(attrs={"class": "form-control selectpicker"}),
"location": forms.Select(attrs={"class": "form-control selectpicker"}),
"body_side": forms.Select(attrs={"class": "form-control selectpicker"}),
"nb_week_off": forms.NumberInput(
attrs={"class": "form-control", "placeholder": "xx"}
),
"diagnosis": forms.Textarea(
attrs={
"class": "form-control",
"placeholder": "Informations about diagnosis", # pylint: disable=line-too-long
}
),
"informations": forms.Textarea(
attrs={
"class": "form-control",
"placeholder": "Informations about accident: context (why, where, …), consequencies, re-education exercices, …", # pylint: disable=line-too-long
"placeholder": "Informations about injury: consequencies, re-education exercices, …", # pylint: disable=line-too-long
}
),
}

View File

@ -1,10 +1,7 @@
from django.db import models
from django.contrib.auth import get_user_model
User = get_user_model()
from datetime import date
import pendulum
from ultron.tools.models import Markdownizable, Seasonisable
from ultron.people.models import Gymnast
@ -12,6 +9,20 @@ from ultron.planning.models import Event
from ultron.objective.models import Educative, Skill, Routine
from ultron.location.models import Club
User = get_user_model()
INJURY_MECHANISM_CHOICE = (
(0, "Overuse"),
(1, "Trauma"),
)
INJURY_BODY_SIDE_CHOICE = (
(0, "Not Applicable"),
(1, "Left"),
(2, "Right"),
(3, "Both"),
)
ROUTINE_TYPE_CHOICE = (
(0, "Other"),
(1, "Q1R1"),
@ -126,6 +137,21 @@ class ChronoDetails(models.Model):
value = models.DecimalField(max_digits=5, decimal_places=3)
class InjuryLocation(models.Model):
"""
Classe représentant les localisations de blessures
"""
class Meta:
verbose_name = "Injury Location"
verbose_name_plural = "Injury Locations"
label = models.CharField(max_length=100, null=False, blank=False)
def __str__(self):
return f"{self.label}"
class Injury(Markdownizable, Seasonisable):
"""
La classe `Injury` permet d'indiquer qu'un gymnaste a eu une blessure, en liaison avec un
@ -140,18 +166,36 @@ class Injury(Markdownizable, Seasonisable):
gymnast = models.ForeignKey(
Gymnast,
verbose_name="Gymnast",
related_name="accident",
related_name="injuries",
on_delete=models.CASCADE,
)
skill = models.ForeignKey(
"objective.Skill",
verbose_name="Skill",
related_name="accident",
related_name="injuries",
on_delete=models.SET_NULL,
default=None,
blank=True,
null=True,
)
# location = models.ForeignKey(
# InjuryLocation,
# verbose_name="Location",
# related_name="injuries",
# on_delete=models.CASCADE,
# )
body_side = models.PositiveSmallIntegerField(
choices=INJURY_BODY_SIDE_CHOICE, verbose_name="Body side"
)
mechanism = models.PositiveSmallIntegerField(
choices=INJURY_MECHANISM_CHOICE, verbose_name="Injury mechanism"
)
diagnosis = models.TextField(
null=True,
blank=True,
verbose_name="Diagnosis",
help_text="Only normal text is authorized",
)
nb_week_off = models.SmallIntegerField(
blank=True, null=True, verbose_name="# week off"
)
@ -159,10 +203,7 @@ class Injury(Markdownizable, Seasonisable):
updated_at = models.DateTimeField(auto_now=True)
def __str__(self):
return "%s (%s)" % (
self.gymnast,
self.date,
)
return f"{self.gymnast} ({self.date}): {self.mechanism} on {self.location} {self.body_side}"
def timeline_representation(self):
return f"<li>{self.date:%d %b %Y} - Inuried on ({self.skill}): {self.nb_week_off} (weeks off)</li>"