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
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
5 changed files with 454 additions and 175 deletions

File diff suppressed because it is too large Load Diff

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

View File

@ -219,6 +219,38 @@ class ParticipantRegistration(Registration):
def form_class(self): # pragma: no cover
raise NotImplementedError
def registration_informations(self):
informations = []
if not self.team:
text = _("You are not in a team. You can <a href=\"{create_url}\">create one</a> "
"or <a href=\"{join_url}\">join an existing one</a> to participate.")
create_url = reverse_lazy("participation:create_team")
join_url = reverse_lazy("participation:join_team")
content = format_lazy(text, create_url=create_url, join_url=join_url)
informations.append({
'title': _("No team"),
'type': "danger",
'priority': 1,
'content': content,
})
else:
if self.team.participation.tournament:
if not self.photo_authorization:
text = _("You have not uploaded your photo authorization. "
"You can do it by clicking on <a href=\"{photo_url}\">this link</a>.")
photo_url = reverse_lazy("registration:upload_user_photo_authorization", args=(self.id,))
content = format_lazy(text, photo_url=photo_url)
informations.append({
'title': _("Photo authorization"),
'type': "danger",
'priority': 5,
'content': content,
})
informations.extend(self.team.important_informations())
return informations
class Meta:
verbose_name = _("participant registration")
verbose_name_plural = _("participant registrations")
@ -294,6 +326,45 @@ class StudentRegistration(ParticipantRegistration):
from registration.forms import StudentRegistrationForm
return StudentRegistrationForm
def registration_informations(self):
informations = super().registration_informations()
if self.team and self.team.participation.tournament and self.under_18:
if not self.parental_authorization:
text = _("You have not uploaded your parental authorization. "
"You can do it by clicking on <a href=\"{parental_url}\">this link</a>.")
parental_url = reverse_lazy("registration:upload_user_parental_authorization", args=(self.id,))
content = format_lazy(text, parental_url=parental_url)
informations.append({
'title': _("Parental authorization"),
'type': "danger",
'priority': 5,
'content': content,
})
if not self.health_sheet:
text = _("You have not uploaded your health sheet. "
"You can do it by clicking on <a href=\"{health_url}\">this link</a>.")
health_url = reverse_lazy("registration:upload_user_health_sheet", args=(self.id,))
content = format_lazy(text, health_url=health_url)
informations.append({
'title': _("Health sheet"),
'type': "danger",
'priority': 5,
'content': content,
})
if not self.vaccine_sheet:
text = _("You have not uploaded your vaccine sheet. "
"You can do it by clicking on <a href=\"{vaccine_url}\">this link</a>.")
vaccine_url = reverse_lazy("registration:upload_user_vaccine_sheet", args=(self.id,))
content = format_lazy(text, vaccine_url=vaccine_url)
informations.append({
'title': _("Vaccine sheet"),
'type': "danger",
'priority': 5,
'content': content,
})
return informations
class Meta:
verbose_name = _("student registration")
verbose_name_plural = _("student registrations")

View File

@ -7,11 +7,11 @@
</div>
<div class="card-body">
{% for information in user.registration.important_informations %}
<div class="card">
<div class="card my-2">
<div class="card-header bg-dark-subtle">
<h4 class="card-title">{{ information.title }}</h4>
<h5 class="card-title">{{ information.title }}</h5>
</div>
<div class="card-body bg-warning-subtle">
<div class="card-body bg-{{ information.type }}-subtle">
{{ information.content|safe }}
</div>
</div>