1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-06-21 01:18:22 +02:00

First important informations

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello
2024-02-11 20:20:28 +01:00
parent e7c207d2af
commit acd1d80c75
5 changed files with 454 additions and 175 deletions

View File

@ -66,6 +66,88 @@ class Team(models.Model):
def coaches(self):
return self.participants.filter(coachregistration__isnull=False)
def can_validate(self):
if self.students.count() < 4:
return False
if not self.coaches.exists():
return False
if not self.participation.tournament:
return False
if any(not r.photo_authorization for r in self.participants.all()):
return False
if not self.motivation_letter:
return False
if not self.participation.tournament.remote:
if any(r.under_18 and not r.health_sheet for r in self.students.all()):
return False
if any(r.under_18 and not r.vaccine_sheet for r in self.students.all()):
return False
if any(r.under_18 and not r.parental_authorization for r in self.students.all()):
return False
return True
def important_informations(self):
informations = []
if self.participation.valid is None:
if not self.participation.tournament:
text = _("The team is not registered to any tournament. "
"You can register the team to a tournament using <a href='{url}'>this link</a>.")
url = reverse_lazy("participation:update_team", args=(self.pk,))
content = format_lazy(text, url=url)
informations.append({
'title': _("No tournament"),
'type': "danger",
'priority': 4,
'content': content,
})
elif not self.motivation_letter:
text = _("The team has not uploaded a motivation letter. "
"You can upload your motivation letter using <a href='{url}'>this link</a>.")
url = reverse_lazy("participation:upload_team_motivation_letter", args=(self.pk,))
content = format_lazy(text, url=url)
informations.append({
'title': _("No motivation letter"),
'type': "danger",
'priority': 10,
'content': content,
})
if (nb_students := self.students.count()) < 4:
text = _("The team has less than 4 students ({nb_students})."
"You can invite more students to join the team using the invite code <strong>{code}</strong>.")
content = format_lazy(text, nb_students=nb_students, code=self.access_code)
informations.append({
'title': _("Not enough students"),
'type': "warning",
'priority': 7,
'content': content,
})
if not self.coaches.exists():
text = _("The team has no coach."
"You can invite a coach to join the team using the invite code <strong>{code}</strong>.")
content = format_lazy(text, nb_students=nb_students, code=self.access_code)
informations.append({
'title': _("No coach"),
'type': "warning",
'priority': 8,
'content': content,
})
if (nb_students := self.students.count()) > 6 or self.coaches.count() > 2:
text = _("The team has more than 6 students ({nb_students}) or more than 2 coaches ({nb_coaches})."
"You have to restrict the number of students and coaches to 6 and 2, respectively.")
content = format_lazy(text, nb_students=nb_students, nb_coaches=self.coaches.count())
informations.append({
'title': _("Too many members"),
'type': "warning",
'priority': 7,
'content': content,
})
return informations
@property
def email(self):
"""

View File

@ -180,15 +180,7 @@ class TeamDetailView(LoginRequiredMixin, FormMixin, ProcessFormView, DetailView)
context["validation_form"] = ValidateParticipationForm(self.request.POST or None)
# A team is complete when there are at least 4 members plus a coache that have sent their authorizations,
# their health sheet, they confirmed their email address and under-18 people sent their parental authorization.
# TODO: Add vaccine sheets
context["can_validate"] = team.students.count() >= 4 and team.coaches.exists() and \
team.participation.tournament and \
all(r.photo_authorization for r in team.participants.all()) and \
(team.participation.tournament.remote
or all(r.health_sheet for r in team.students.all() if r.under_18)) and \
(team.participation.tournament.remote
or all(r.parental_authorization for r in team.students.all() if r.under_18)) and \
team.motivation_letter
context["can_validate"] = team.can_validate()
return context