2020-12-27 10:49:54 +00:00
|
|
|
# Copyright (C) 2020 by Animath
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2024-02-18 23:17:14 +00:00
|
|
|
from datetime import date, datetime
|
2020-12-29 15:14:56 +00:00
|
|
|
|
2020-12-27 10:49:54 +00:00
|
|
|
from django.contrib.sites.models import Site
|
2024-02-23 17:02:24 +00:00
|
|
|
from django.core.mail import send_mail
|
2023-01-10 19:24:06 +00:00
|
|
|
from django.core.validators import MaxValueValidator, MinValueValidator
|
2020-12-27 10:49:54 +00:00
|
|
|
from django.db import models
|
|
|
|
from django.template import loader
|
2024-02-23 22:05:10 +00:00
|
|
|
from django.urls import reverse, reverse_lazy
|
2024-02-23 17:02:24 +00:00
|
|
|
from django.utils import timezone, translation
|
2020-12-27 10:49:54 +00:00
|
|
|
from django.utils.crypto import get_random_string
|
|
|
|
from django.utils.encoding import force_bytes
|
|
|
|
from django.utils.http import urlsafe_base64_encode
|
2024-02-11 18:21:27 +00:00
|
|
|
from django.utils.text import format_lazy
|
2020-12-27 10:49:54 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2020-12-28 22:59:21 +00:00
|
|
|
from phonenumber_field.modelfields import PhoneNumberField
|
2020-12-27 10:49:54 +00:00
|
|
|
from polymorphic.models import PolymorphicModel
|
2024-02-18 23:17:14 +00:00
|
|
|
from tfjm import helloasso
|
2020-12-28 18:19:01 +00:00
|
|
|
from tfjm.tokens import email_validation_token
|
2020-12-27 10:49:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Registration(PolymorphicModel):
|
|
|
|
"""
|
|
|
|
Registrations store extra content that are not asked in the User Model.
|
|
|
|
This is specific to the role of the user, see StudentRegistration,
|
2023-02-19 23:23:18 +00:00
|
|
|
CoachRegistration or VolunteerRegistration.
|
2020-12-27 10:49:54 +00:00
|
|
|
"""
|
|
|
|
user = models.OneToOneField(
|
|
|
|
"auth.User",
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
verbose_name=_("user"),
|
|
|
|
)
|
|
|
|
|
|
|
|
give_contact_to_animath = models.BooleanField(
|
|
|
|
default=False,
|
|
|
|
verbose_name=_("Grant Animath to contact me in the future about other actions"),
|
|
|
|
)
|
|
|
|
|
|
|
|
email_confirmed = models.BooleanField(
|
|
|
|
default=False,
|
|
|
|
verbose_name=_("email confirmed"),
|
|
|
|
)
|
|
|
|
|
|
|
|
def send_email_validation_link(self):
|
|
|
|
"""
|
|
|
|
The account got created or the email got changed.
|
|
|
|
Send an email that contains a link to validate the address.
|
|
|
|
"""
|
2021-01-18 14:52:09 +00:00
|
|
|
subject = "[TFJM²] " + str(_("Activate your TFJM² account"))
|
2020-12-27 10:49:54 +00:00
|
|
|
token = email_validation_token.make_token(self.user)
|
|
|
|
uid = urlsafe_base64_encode(force_bytes(self.user.pk))
|
|
|
|
site = Site.objects.first()
|
|
|
|
message = loader.render_to_string('registration/mails/email_validation_email.txt',
|
|
|
|
{
|
|
|
|
'user': self.user,
|
|
|
|
'domain': site.domain,
|
|
|
|
'token': token,
|
|
|
|
'uid': uid,
|
|
|
|
})
|
|
|
|
html = loader.render_to_string('registration/mails/email_validation_email.html',
|
|
|
|
{
|
|
|
|
'user': self.user,
|
|
|
|
'domain': site.domain,
|
|
|
|
'token': token,
|
|
|
|
'uid': uid,
|
|
|
|
})
|
|
|
|
self.user.email_user(subject, message, html_message=html)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def type(self): # pragma: no cover
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
@property
|
|
|
|
def form_class(self): # pragma: no cover
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
@property
|
|
|
|
def participates(self):
|
2020-12-29 15:14:56 +00:00
|
|
|
return isinstance(self, ParticipantRegistration)
|
2020-12-27 10:49:54 +00:00
|
|
|
|
2024-02-20 21:54:12 +00:00
|
|
|
@property
|
|
|
|
def is_student(self):
|
|
|
|
return isinstance(self, StudentRegistration)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_coach(self):
|
|
|
|
return isinstance(self, CoachRegistration)
|
|
|
|
|
2020-12-27 10:49:54 +00:00
|
|
|
@property
|
|
|
|
def is_admin(self):
|
2023-02-19 23:23:18 +00:00
|
|
|
return isinstance(self, VolunteerRegistration) and self.admin or self.user.is_superuser
|
2020-12-27 10:49:54 +00:00
|
|
|
|
2021-01-17 11:40:23 +00:00
|
|
|
@property
|
|
|
|
def is_volunteer(self):
|
|
|
|
return isinstance(self, VolunteerRegistration)
|
|
|
|
|
2020-12-27 10:49:54 +00:00
|
|
|
def get_absolute_url(self):
|
|
|
|
return reverse_lazy("registration:user_detail", args=(self.user_id,))
|
|
|
|
|
2024-02-11 18:21:27 +00:00
|
|
|
def registration_informations(self):
|
|
|
|
return []
|
|
|
|
|
|
|
|
def important_informations(self):
|
|
|
|
informations = []
|
|
|
|
if not self.email_confirmed:
|
|
|
|
text = _("Your email address is not validated. Please click on the link you received by email. "
|
|
|
|
"You can resend a mail by clicking on <a href=\"{send_email_url}\">this link</a>.")
|
|
|
|
send_email_url = reverse_lazy("registration:email_validation_resend", args=(self.user_id,))
|
|
|
|
content = format_lazy(text, send_email_url=send_email_url)
|
|
|
|
informations.append({
|
|
|
|
'title': "Validation e-mail",
|
|
|
|
'type': "warning",
|
|
|
|
'priority': 0,
|
|
|
|
'content': content,
|
|
|
|
})
|
|
|
|
|
|
|
|
informations.extend(self.registration_informations())
|
|
|
|
|
|
|
|
informations.sort(key=lambda info: (info['priority'], info['title']))
|
|
|
|
return informations
|
|
|
|
|
2020-12-27 10:49:54 +00:00
|
|
|
def __str__(self):
|
|
|
|
return f"{self.user.first_name} {self.user.last_name}"
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _("registration")
|
|
|
|
verbose_name_plural = _("registrations")
|
|
|
|
|
|
|
|
|
2020-12-28 11:59:12 +00:00
|
|
|
def get_random_photo_filename(instance, filename):
|
2020-12-27 10:49:54 +00:00
|
|
|
return "authorization/photo/" + get_random_string(64)
|
|
|
|
|
|
|
|
|
2020-12-28 11:59:12 +00:00
|
|
|
def get_random_health_filename(instance, filename):
|
|
|
|
return "authorization/health/" + get_random_string(64)
|
|
|
|
|
|
|
|
|
2023-02-19 23:38:57 +00:00
|
|
|
def get_random_vaccine_filename(instance, filename):
|
|
|
|
return "authorization/vaccine/" + get_random_string(64)
|
|
|
|
|
|
|
|
|
2020-12-28 11:59:12 +00:00
|
|
|
def get_random_parental_filename(instance, filename):
|
|
|
|
return "authorization/parental/" + get_random_string(64)
|
|
|
|
|
|
|
|
|
|
|
|
class ParticipantRegistration(Registration):
|
2020-12-27 10:49:54 +00:00
|
|
|
team = models.ForeignKey(
|
|
|
|
"participation.Team",
|
2020-12-28 11:59:12 +00:00
|
|
|
related_name="participants",
|
2020-12-27 10:49:54 +00:00
|
|
|
on_delete=models.PROTECT,
|
2020-12-28 11:59:12 +00:00
|
|
|
blank=True,
|
2020-12-27 10:49:54 +00:00
|
|
|
null=True,
|
|
|
|
default=None,
|
|
|
|
verbose_name=_("team"),
|
|
|
|
)
|
|
|
|
|
2021-01-22 08:04:44 +00:00
|
|
|
gender = models.CharField(
|
|
|
|
max_length=6,
|
2021-01-22 07:45:00 +00:00
|
|
|
verbose_name=_("gender"),
|
|
|
|
choices=[
|
|
|
|
("female", _("Female")),
|
|
|
|
("male", _("Male")),
|
|
|
|
("other", _("Other")),
|
|
|
|
],
|
|
|
|
default="other",
|
|
|
|
)
|
|
|
|
|
2023-01-10 19:24:06 +00:00
|
|
|
address = models.CharField(
|
|
|
|
max_length=255,
|
2020-12-28 22:59:21 +00:00
|
|
|
verbose_name=_("address"),
|
2023-01-10 19:24:06 +00:00
|
|
|
)
|
|
|
|
|
2023-01-16 22:14:44 +00:00
|
|
|
zip_code = models.PositiveIntegerField(
|
2023-01-10 19:24:06 +00:00
|
|
|
verbose_name=_("zip code"),
|
|
|
|
validators=[MinValueValidator(1000), MaxValueValidator(99999)],
|
|
|
|
)
|
|
|
|
|
|
|
|
city = models.CharField(
|
|
|
|
max_length=255,
|
|
|
|
verbose_name=_("city"),
|
2020-12-28 22:59:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
phone_number = PhoneNumberField(
|
|
|
|
verbose_name=_("phone number"),
|
|
|
|
blank=True,
|
|
|
|
)
|
|
|
|
|
2021-01-23 20:55:54 +00:00
|
|
|
health_issues = models.TextField(
|
|
|
|
verbose_name=_("health issues"),
|
|
|
|
blank=True,
|
2024-01-16 21:26:00 +00:00
|
|
|
help_text=_("You can indicate here your allergies or anything that is important to know for organizers."),
|
|
|
|
)
|
|
|
|
|
|
|
|
housing_constraints = models.TextField(
|
|
|
|
verbose_name=_("housing constraints"),
|
|
|
|
blank=True,
|
|
|
|
help_text=_("You can fill in something here if you have any housing constraints, "
|
|
|
|
"e.g. medical problems, scheduling issues, gender issues, "
|
|
|
|
"or anything else you feel is relevant to the organizers. "
|
|
|
|
"Leave empty if you have nothing specific to declare."),
|
2021-01-23 20:55:54 +00:00
|
|
|
)
|
|
|
|
|
2020-12-28 11:59:12 +00:00
|
|
|
photo_authorization = models.FileField(
|
|
|
|
verbose_name=_("photo authorization"),
|
|
|
|
upload_to=get_random_photo_filename,
|
|
|
|
blank=True,
|
|
|
|
default="",
|
|
|
|
)
|
|
|
|
|
2020-12-29 15:14:56 +00:00
|
|
|
@property
|
|
|
|
def under_18(self):
|
2023-01-10 19:31:43 +00:00
|
|
|
if isinstance(self, CoachRegistration):
|
|
|
|
return False # In normal case
|
2021-01-23 13:30:00 +00:00
|
|
|
important_date = timezone.now().date()
|
|
|
|
if self.team and self.team.participation.tournament:
|
|
|
|
important_date = self.team.participation.tournament.date_start
|
|
|
|
if self.team.participation.final:
|
|
|
|
from participation.models import Tournament
|
|
|
|
important_date = Tournament.final_tournament().date_start
|
|
|
|
return (important_date - self.birth_date).days < 18 * 365.24
|
2020-12-29 15:14:56 +00:00
|
|
|
|
2020-12-28 11:59:12 +00:00
|
|
|
@property
|
2020-12-28 17:52:50 +00:00
|
|
|
def type(self): # pragma: no cover
|
2020-12-28 11:59:12 +00:00
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
@property
|
2020-12-28 17:52:50 +00:00
|
|
|
def form_class(self): # pragma: no cover
|
2020-12-28 11:59:12 +00:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2024-02-11 19:20:28 +00:00
|
|
|
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
|
|
|
|
|
2023-04-03 17:13:15 +00:00
|
|
|
class Meta:
|
|
|
|
verbose_name = _("participant registration")
|
|
|
|
verbose_name_plural = _("participant registrations")
|
|
|
|
|
|
|
|
|
2020-12-28 11:59:12 +00:00
|
|
|
class StudentRegistration(ParticipantRegistration):
|
|
|
|
"""
|
|
|
|
Specific registration for students.
|
|
|
|
They have a team, a student class and a school.
|
|
|
|
"""
|
2023-01-10 19:31:43 +00:00
|
|
|
birth_date = models.DateField(
|
|
|
|
verbose_name=_("birth date"),
|
|
|
|
default=date.today,
|
|
|
|
)
|
|
|
|
|
2020-12-27 10:49:54 +00:00
|
|
|
student_class = models.IntegerField(
|
|
|
|
choices=[
|
|
|
|
(12, _("12th grade")),
|
|
|
|
(11, _("11th grade")),
|
|
|
|
(10, _("10th grade or lower")),
|
|
|
|
],
|
|
|
|
verbose_name=_("student class"),
|
|
|
|
)
|
|
|
|
|
|
|
|
school = models.CharField(
|
|
|
|
max_length=255,
|
|
|
|
verbose_name=_("school"),
|
|
|
|
)
|
|
|
|
|
2020-12-28 22:59:21 +00:00
|
|
|
responsible_name = models.CharField(
|
|
|
|
max_length=255,
|
|
|
|
verbose_name=_("responsible name"),
|
|
|
|
default="",
|
|
|
|
)
|
|
|
|
|
|
|
|
responsible_phone = PhoneNumberField(
|
|
|
|
verbose_name=_("responsible phone number"),
|
2023-01-10 19:31:43 +00:00
|
|
|
default="",
|
2020-12-28 22:59:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
responsible_email = models.EmailField(
|
|
|
|
verbose_name=_("responsible email address"),
|
|
|
|
default="",
|
|
|
|
)
|
|
|
|
|
2020-12-28 11:59:12 +00:00
|
|
|
parental_authorization = models.FileField(
|
|
|
|
verbose_name=_("parental authorization"),
|
|
|
|
upload_to=get_random_parental_filename,
|
2020-12-27 10:49:54 +00:00
|
|
|
blank=True,
|
|
|
|
default="",
|
|
|
|
)
|
|
|
|
|
2021-01-21 20:55:19 +00:00
|
|
|
health_sheet = models.FileField(
|
|
|
|
verbose_name=_("health sheet"),
|
|
|
|
upload_to=get_random_health_filename,
|
|
|
|
blank=True,
|
|
|
|
default="",
|
|
|
|
)
|
|
|
|
|
2023-02-19 23:38:57 +00:00
|
|
|
vaccine_sheet = models.FileField(
|
|
|
|
verbose_name=_("vaccine sheet"),
|
|
|
|
upload_to=get_random_vaccine_filename,
|
|
|
|
blank=True,
|
|
|
|
default="",
|
|
|
|
)
|
|
|
|
|
2020-12-27 10:49:54 +00:00
|
|
|
@property
|
|
|
|
def type(self):
|
|
|
|
return _("student")
|
|
|
|
|
|
|
|
@property
|
|
|
|
def form_class(self):
|
|
|
|
from registration.forms import StudentRegistrationForm
|
|
|
|
return StudentRegistrationForm
|
|
|
|
|
2024-02-11 19:20:28 +00:00
|
|
|
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,
|
|
|
|
})
|
|
|
|
|
2024-02-11 22:31:24 +00:00
|
|
|
if self.team and self.team.participation.valid:
|
2024-02-12 21:30:27 +00:00
|
|
|
for payment in self.payments.all():
|
|
|
|
if payment.valid is False:
|
|
|
|
text = _("You have to pay {amount} € for your registration, or send a scholarship "
|
|
|
|
"notification or a payment proof. "
|
|
|
|
"You can do it on <a href=\"{url}\">the payment page</a>.")
|
|
|
|
url = reverse_lazy("registration:update_payment", args=(payment.id,))
|
|
|
|
content = format_lazy(text, amount=payment.amount, url=url)
|
|
|
|
informations.append({
|
|
|
|
'title': _("Payment"),
|
|
|
|
'type': "danger",
|
|
|
|
'priority': 3,
|
|
|
|
'content': content,
|
|
|
|
})
|
|
|
|
elif self.payment.valid is None:
|
|
|
|
text = _("Your payment is under approval.")
|
|
|
|
content = text
|
|
|
|
informations.append({
|
|
|
|
'title': _("Payment"),
|
|
|
|
'type': "warning",
|
|
|
|
'priority': 3,
|
|
|
|
'content': content,
|
|
|
|
})
|
2024-02-11 22:31:24 +00:00
|
|
|
|
2024-02-11 19:20:28 +00:00
|
|
|
return informations
|
|
|
|
|
2020-12-27 10:49:54 +00:00
|
|
|
class Meta:
|
|
|
|
verbose_name = _("student registration")
|
|
|
|
verbose_name_plural = _("student registrations")
|
|
|
|
|
|
|
|
|
2020-12-28 11:59:12 +00:00
|
|
|
class CoachRegistration(ParticipantRegistration):
|
2020-12-27 10:49:54 +00:00
|
|
|
"""
|
|
|
|
Specific registration for coaches.
|
|
|
|
They have a team and a professional activity.
|
|
|
|
"""
|
2024-01-20 17:26:52 +00:00
|
|
|
last_degree = models.CharField(
|
|
|
|
max_length=255,
|
|
|
|
default="",
|
|
|
|
verbose_name=_("most recent degree in mathematics, computer science or physics"),
|
|
|
|
help_text=_("Your most recent degree in maths, computer science or physics, "
|
|
|
|
"or your last entrance exam (CAPES, Agrégation,…)"),
|
|
|
|
)
|
|
|
|
|
2020-12-27 10:49:54 +00:00
|
|
|
professional_activity = models.TextField(
|
|
|
|
verbose_name=_("professional activity"),
|
|
|
|
)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def type(self):
|
|
|
|
return _("coach")
|
|
|
|
|
|
|
|
@property
|
|
|
|
def form_class(self):
|
|
|
|
from registration.forms import CoachRegistrationForm
|
|
|
|
return CoachRegistrationForm
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _("coach registration")
|
|
|
|
verbose_name_plural = _("coach registrations")
|
|
|
|
|
|
|
|
|
2020-12-28 11:59:12 +00:00
|
|
|
class VolunteerRegistration(Registration):
|
|
|
|
"""
|
|
|
|
Specific registration for organizers and juries.
|
|
|
|
"""
|
|
|
|
professional_activity = models.TextField(
|
|
|
|
verbose_name=_("professional activity"),
|
|
|
|
)
|
|
|
|
|
2023-02-19 23:23:18 +00:00
|
|
|
admin = models.BooleanField(
|
|
|
|
verbose_name=_("administrator"),
|
|
|
|
help_text=_("An administrator has all rights. Please don't give this right to all juries and volunteers."),
|
|
|
|
default=False,
|
|
|
|
)
|
|
|
|
|
2021-01-17 11:40:23 +00:00
|
|
|
@property
|
|
|
|
def interesting_tournaments(self) -> set:
|
|
|
|
return set(self.organized_tournaments.all()).union(map(lambda pool: pool.tournament, self.jury_in.all()))
|
|
|
|
|
2020-12-28 11:59:12 +00:00
|
|
|
@property
|
|
|
|
def type(self):
|
2023-02-19 23:23:18 +00:00
|
|
|
return _('admin') if self.is_admin else _('volunteer')
|
2020-12-28 11:59:12 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def form_class(self):
|
|
|
|
from registration.forms import VolunteerRegistrationForm
|
|
|
|
return VolunteerRegistrationForm
|
|
|
|
|
2024-02-11 21:39:11 +00:00
|
|
|
def important_informations(self):
|
|
|
|
informations = []
|
|
|
|
|
|
|
|
for tournament in self.organized_tournaments.all():
|
|
|
|
if timezone.now() < tournament.inscription_limit \
|
|
|
|
or tournament.participations.filter(valid=True).count() < tournament.max_teams:
|
|
|
|
text = _("Registrations for tournament {tournament} are closing on {date:%Y-%m-%d %H:%M}. "
|
|
|
|
"There are for now {validated_teams} validated teams (+ {pending_teams} pending) "
|
|
|
|
"on {max_teams} expected.")
|
|
|
|
content = format_lazy(text, tournament=tournament.name, date=tournament.inscription_limit,
|
|
|
|
validated_teams=tournament.participations.filter(valid=True).count(),
|
|
|
|
pending_teams=tournament.participations.filter(valid=False).count(),
|
|
|
|
max_teams=tournament.max_teams)
|
|
|
|
informations.append({
|
|
|
|
'title': _("Registrations"),
|
|
|
|
'type': "info",
|
|
|
|
'priority': 2,
|
|
|
|
'content': content,
|
|
|
|
})
|
|
|
|
|
|
|
|
for pending_participation in tournament.participations.filter(valid=False).all():
|
|
|
|
text = _("The team {trigram} requested to be validated for the tournament of {tournament}. "
|
|
|
|
"You can check the status of the team on the <a href=\"{url}\">team page</a>.")
|
|
|
|
url = reverse_lazy("participation:team_detail", args=(pending_participation.team.id,))
|
|
|
|
content = format_lazy(text, trigram=pending_participation.team.trigram,
|
|
|
|
tournament=tournament.name, url=url)
|
|
|
|
informations.append({
|
|
|
|
'title': _("Pending validation"),
|
|
|
|
'type': "warning",
|
|
|
|
'priority': 4,
|
|
|
|
'content': content,
|
|
|
|
})
|
|
|
|
|
2024-02-23 21:58:23 +00:00
|
|
|
payments = Payment.objects.filter(registrations__team__participation__tournament=tournament).all()
|
|
|
|
valid = payments.filter(valid=True).count()
|
|
|
|
pending = payments.filter(valid=None).count()
|
|
|
|
invalid = payments.filter(valid=False).count()
|
|
|
|
if pending + invalid > 0:
|
|
|
|
text = _("There are {valid} validated payments, {pending} pending and {invalid} invalid for the "
|
|
|
|
"tournament of {tournament}. You can check the status of the payments on the "
|
|
|
|
"<a href=\"{url}\">payments list</a>.")
|
|
|
|
url = reverse_lazy("participation:tournament_payments", args=(tournament.id,))
|
|
|
|
content = format_lazy(text, valid=valid, pending=pending, invalid=invalid, tournament=tournament.name,
|
|
|
|
url=url)
|
|
|
|
informations.append({
|
|
|
|
'title': _("Payments"),
|
|
|
|
'type': "info",
|
|
|
|
'priority': 5,
|
|
|
|
'content': content,
|
|
|
|
})
|
|
|
|
|
2024-02-11 21:39:11 +00:00
|
|
|
return informations
|
|
|
|
|
2023-04-03 17:13:15 +00:00
|
|
|
class Meta:
|
|
|
|
verbose_name = _("volunteer registration")
|
|
|
|
verbose_name_plural = _("volunteer registrations")
|
|
|
|
|
2020-12-28 11:59:12 +00:00
|
|
|
|
2024-02-18 21:36:01 +00:00
|
|
|
def get_receipt_filename(instance, filename):
|
|
|
|
return f"authorization/receipt/receipt_{instance.id}"
|
2021-01-18 15:35:37 +00:00
|
|
|
|
|
|
|
|
2024-02-21 21:44:50 +00:00
|
|
|
def get_random_token():
|
|
|
|
return get_random_string(32)
|
|
|
|
|
|
|
|
|
2021-01-18 15:35:37 +00:00
|
|
|
class Payment(models.Model):
|
2024-02-12 21:30:27 +00:00
|
|
|
registrations = models.ManyToManyField(
|
2021-01-18 15:35:37 +00:00
|
|
|
ParticipantRegistration,
|
2024-02-12 21:30:27 +00:00
|
|
|
related_name="payments",
|
|
|
|
verbose_name=_("registrations"),
|
|
|
|
)
|
|
|
|
|
|
|
|
grouped = models.BooleanField(
|
|
|
|
verbose_name=_("grouped"),
|
|
|
|
default=False,
|
|
|
|
help_text=_("If set to true, then one payment is made for the full team, "
|
|
|
|
"for example if the school pays for all."),
|
|
|
|
)
|
|
|
|
|
|
|
|
amount = models.PositiveSmallIntegerField(
|
|
|
|
verbose_name=_("total amount"),
|
|
|
|
help_text=_("Corresponds to the total required amount to pay, in euros."),
|
|
|
|
default=0,
|
|
|
|
)
|
|
|
|
|
2024-02-21 21:44:50 +00:00
|
|
|
token = models.CharField(
|
|
|
|
verbose_name=_("token"),
|
|
|
|
max_length=32,
|
|
|
|
default=get_random_token,
|
|
|
|
help_text=_("A token to authorize external users to make this payment."),
|
|
|
|
)
|
|
|
|
|
2024-02-12 21:30:27 +00:00
|
|
|
final = models.BooleanField(
|
|
|
|
verbose_name=_("for final tournament"),
|
|
|
|
default=False,
|
2021-01-18 15:35:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type = models.CharField(
|
|
|
|
verbose_name=_("type"),
|
|
|
|
max_length=16,
|
|
|
|
choices=[
|
|
|
|
('', _("No payment")),
|
2024-02-18 21:36:01 +00:00
|
|
|
('helloasso', _("Credit card")),
|
2021-01-18 15:35:37 +00:00
|
|
|
('scholarship', _("Scholarship")),
|
|
|
|
('bank_transfer', _("Bank transfer")),
|
2022-04-26 11:47:15 +00:00
|
|
|
('other', _("Other (please indicate)")),
|
2021-01-18 15:35:37 +00:00
|
|
|
('free', _("The tournament is free")),
|
|
|
|
],
|
|
|
|
blank=True,
|
|
|
|
default="",
|
|
|
|
)
|
|
|
|
|
2024-02-12 21:30:27 +00:00
|
|
|
checkout_intent_id = models.IntegerField(
|
|
|
|
verbose_name=_("Hello Asso checkout intent ID"),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
default=None,
|
|
|
|
)
|
|
|
|
|
|
|
|
receipt = models.FileField(
|
|
|
|
verbose_name=_("receipt"),
|
|
|
|
help_text=_("only if you have a scholarship or if you chose a bank transfer."),
|
2024-02-18 21:36:01 +00:00
|
|
|
upload_to=get_receipt_filename,
|
2021-01-18 15:35:37 +00:00
|
|
|
blank=True,
|
|
|
|
default="",
|
|
|
|
)
|
|
|
|
|
|
|
|
additional_information = models.TextField(
|
|
|
|
verbose_name=_("additional information"),
|
|
|
|
help_text=_("To help us to find your payment."),
|
|
|
|
blank=True,
|
|
|
|
default="",
|
|
|
|
)
|
|
|
|
|
|
|
|
valid = models.BooleanField(
|
2023-04-05 08:44:27 +00:00
|
|
|
verbose_name=_("payment valid"),
|
2021-01-18 15:35:37 +00:00
|
|
|
null=True,
|
|
|
|
default=False,
|
|
|
|
)
|
2021-01-18 17:13:58 +00:00
|
|
|
|
2024-02-20 21:54:12 +00:00
|
|
|
@property
|
|
|
|
def team(self):
|
|
|
|
return self.registrations.first().team
|
2024-02-23 20:43:44 +00:00
|
|
|
team.fget.short_description = _("team")
|
|
|
|
team.fget.admin_order_field = 'registrations__team__trigram'
|
2024-02-20 21:54:12 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def tournament(self):
|
|
|
|
if self.final:
|
|
|
|
from participation.models import Tournament
|
|
|
|
return Tournament.final_tournament()
|
|
|
|
return self.registrations.first().team.participation.tournament
|
2024-02-23 20:43:44 +00:00
|
|
|
tournament.fget.short_description = _("tournament")
|
|
|
|
tournament.fget.admin_order_field = 'registrations__team__participation__tournament'
|
2024-02-20 21:54:12 +00:00
|
|
|
|
2024-02-21 21:44:50 +00:00
|
|
|
def get_checkout_intent(self, none_if_link_disabled=False):
|
2024-02-18 23:17:14 +00:00
|
|
|
if self.checkout_intent_id is None:
|
|
|
|
return None
|
2024-02-21 21:44:50 +00:00
|
|
|
return helloasso.get_checkout_intent(self.checkout_intent_id, none_if_link_disabled=none_if_link_disabled)
|
2024-02-18 23:17:14 +00:00
|
|
|
|
|
|
|
def create_checkout_intent(self):
|
2024-02-21 21:44:50 +00:00
|
|
|
checkout_intent = self.get_checkout_intent(none_if_link_disabled=True)
|
2024-02-18 23:17:14 +00:00
|
|
|
if checkout_intent is not None:
|
|
|
|
return checkout_intent
|
|
|
|
|
2024-02-20 21:54:12 +00:00
|
|
|
tournament = self.tournament
|
2024-02-18 23:17:14 +00:00
|
|
|
year = datetime.now().year
|
|
|
|
base_site = "https://" + Site.objects.first().domain
|
|
|
|
checkout_intent = helloasso.create_checkout_intent(
|
|
|
|
amount=100 * self.amount,
|
2024-02-21 22:56:29 +00:00
|
|
|
name=f"Participation au TFJM² {year} - {tournament.name} - {self.team.trigram}",
|
2024-02-18 23:17:14 +00:00
|
|
|
back_url=base_site + reverse('registration:update_payment', args=(self.id,)),
|
2024-02-20 21:54:12 +00:00
|
|
|
error_url=f"{base_site}{reverse('registration:payment_hello_asso_return', args=(self.id,))}?type=error",
|
|
|
|
return_url=f"{base_site}{reverse('registration:payment_hello_asso_return', args=(self.id,))}?type=return",
|
2024-02-18 23:17:14 +00:00
|
|
|
contains_donation=False,
|
|
|
|
metadata=dict(
|
|
|
|
users=[
|
|
|
|
dict(user_id=registration.user.id,
|
|
|
|
first_name=registration.user.first_name,
|
|
|
|
last_name=registration.user.last_name,
|
|
|
|
email=registration.user.email,)
|
|
|
|
for registration in self.registrations.all()
|
|
|
|
],
|
|
|
|
payment_id=self.id,
|
|
|
|
final=self.final,
|
|
|
|
tournament_id=tournament.id,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.checkout_intent_id = checkout_intent["id"]
|
|
|
|
self.save()
|
|
|
|
|
|
|
|
return checkout_intent
|
|
|
|
|
2024-02-23 17:02:24 +00:00
|
|
|
def send_remind_mail(self):
|
|
|
|
translation.activate('fr')
|
|
|
|
subject = "[TFJM²] " + str(_("Reminder for your payment"))
|
|
|
|
site = Site.objects.first()
|
|
|
|
for registration in self.registrations.all():
|
|
|
|
message = loader.render_to_string('registration/mails/payment_reminder.txt',
|
|
|
|
dict(registration=registration, payment=self, domain=site.domain))
|
|
|
|
html = loader.render_to_string('registration/mails/payment_reminder.html',
|
|
|
|
dict(registration=registration, payment=self, domain=site.domain))
|
|
|
|
registration.user.email_user(subject, message, html_message=html)
|
|
|
|
|
|
|
|
def send_helloasso_payment_confirmation_mail(self):
|
|
|
|
translation.activate('fr')
|
|
|
|
subject = "[TFJM²] " + str(_("Payment confirmation"))
|
|
|
|
site = Site.objects.first()
|
|
|
|
for registration in self.registrations.all():
|
|
|
|
message = loader.render_to_string('registration/mails/payment_confirmation.txt',
|
|
|
|
dict(registration=registration, payment=self, domain=site.domain))
|
|
|
|
html = loader.render_to_string('registration/mails/payment_confirmation.html',
|
|
|
|
dict(registration=registration, payment=self, domain=site.domain))
|
|
|
|
registration.user.email_user(subject, message, html_message=html)
|
|
|
|
|
|
|
|
payer = self.get_checkout_intent()['order']['payer']
|
|
|
|
payer_name = f"{payer['firstName']} {payer['lastName']}"
|
|
|
|
if not self.registrations.filter(user__email=payer['email']).exists():
|
|
|
|
message = loader.render_to_string('registration/mails/payment_confirmation.txt',
|
|
|
|
dict(registration=payer_name, payment=self, domain=site.domain))
|
|
|
|
html = loader.render_to_string('registration/mails/payment_confirmation.html',
|
|
|
|
dict(registration=payer_name, payment=self, domain=site.domain))
|
|
|
|
send_mail(subject, message, None, [payer['email']], html_message=html)
|
|
|
|
|
2021-01-18 19:02:49 +00:00
|
|
|
def get_absolute_url(self):
|
2024-02-12 21:30:27 +00:00
|
|
|
return reverse_lazy("registration:update_payment", args=(self.pk,))
|
2021-01-18 19:02:49 +00:00
|
|
|
|
2021-01-18 21:28:43 +00:00
|
|
|
def __str__(self):
|
2024-02-12 21:30:27 +00:00
|
|
|
return _("Payment of {registrations}").format(registrations=", ".join(map(str, self.registrations.all())))
|
2021-01-18 21:28:43 +00:00
|
|
|
|
2021-01-18 17:13:58 +00:00
|
|
|
class Meta:
|
|
|
|
verbose_name = _("payment")
|
|
|
|
verbose_name_plural = _("payments")
|