mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2024-11-26 11:27:09 +00:00
264 lines
6.2 KiB
Python
264 lines
6.2 KiB
Python
from django.contrib.auth.models import AbstractUser
|
|
from django.db import models
|
|
from django.utils.translation import gettext_lazy as _
|
|
from polymorphic.models import PolymorphicModel
|
|
|
|
from tournament.models import Team, Tournament
|
|
|
|
|
|
class TFJMUser(AbstractUser):
|
|
USERNAME_FIELD = 'email'
|
|
REQUIRED_FIELDS = []
|
|
|
|
email = models.EmailField(
|
|
unique=True,
|
|
verbose_name=_("email"),
|
|
)
|
|
|
|
team = models.ForeignKey(
|
|
Team,
|
|
null=True,
|
|
on_delete=models.SET_NULL,
|
|
related_name="users",
|
|
verbose_name=_("team"),
|
|
)
|
|
|
|
birth_date = models.DateField(
|
|
null=True,
|
|
default=None,
|
|
verbose_name=_("birth date"),
|
|
)
|
|
|
|
gender = models.CharField(
|
|
max_length=16,
|
|
null=True,
|
|
default=None,
|
|
choices=[
|
|
("male", _("Male")),
|
|
("female", _("Female")),
|
|
("non-binary", _("Non binary")),
|
|
],
|
|
verbose_name=_("address"),
|
|
)
|
|
|
|
address = models.CharField(
|
|
max_length=255,
|
|
null=True,
|
|
default=None,
|
|
verbose_name=_("address"),
|
|
)
|
|
|
|
postal_code = models.PositiveSmallIntegerField(
|
|
null=True,
|
|
default=None,
|
|
verbose_name=_("postal code"),
|
|
)
|
|
|
|
city = models.CharField(
|
|
max_length=255,
|
|
null=True,
|
|
default=None,
|
|
verbose_name=_("city"),
|
|
)
|
|
|
|
country = models.CharField(
|
|
max_length=255,
|
|
default="France",
|
|
null=True,
|
|
verbose_name=_("country"),
|
|
)
|
|
|
|
phone_number = models.CharField(
|
|
max_length=20,
|
|
null=True,
|
|
blank=True,
|
|
default=None,
|
|
verbose_name=_("phone number"),
|
|
)
|
|
|
|
school = models.CharField(
|
|
max_length=255,
|
|
null=True,
|
|
default=None,
|
|
verbose_name=_("school"),
|
|
)
|
|
|
|
student_class = models.CharField(
|
|
max_length=16,
|
|
choices=[
|
|
('seconde', _("Seconde or less")),
|
|
('première', _("Première")),
|
|
('terminale', _("Terminale")),
|
|
],
|
|
null=True,
|
|
default=None,
|
|
verbose_name="class",
|
|
)
|
|
|
|
responsible_name = models.CharField(
|
|
max_length=255,
|
|
null=True,
|
|
default=None,
|
|
verbose_name=_("responsible name"),
|
|
)
|
|
|
|
responsible_phone = models.CharField(
|
|
max_length=20,
|
|
null=True,
|
|
default=None,
|
|
verbose_name=_("responsible phone"),
|
|
)
|
|
|
|
responsible_email = models.EmailField(
|
|
null=True,
|
|
default=None,
|
|
verbose_name=_("responsible email"),
|
|
)
|
|
|
|
description = models.TextField(
|
|
null=True,
|
|
default=None,
|
|
verbose_name=_("description"),
|
|
)
|
|
|
|
role = models.CharField(
|
|
max_length=16,
|
|
choices=[
|
|
("admin", _("admin")),
|
|
("organizer", _("organizer")),
|
|
("encadrant", _("encadrant")),
|
|
("participant", _("participant")),
|
|
]
|
|
)
|
|
|
|
year = models.PositiveIntegerField(
|
|
verbose_name=_("year"),
|
|
)
|
|
|
|
class Meta:
|
|
verbose_name = _("user")
|
|
verbose_name_plural = _("users")
|
|
|
|
def save(self, *args, **kwargs):
|
|
self.username = self.email
|
|
super().save(*args, **kwargs)
|
|
|
|
def __str__(self):
|
|
return self.first_name + " " + self.last_name
|
|
|
|
|
|
class Document(PolymorphicModel):
|
|
file = models.FileField(
|
|
unique=True,
|
|
upload_to="files/",
|
|
verbose_name=_("file"),
|
|
)
|
|
|
|
uploaded_at = models.DateTimeField(
|
|
auto_now_add=True,
|
|
verbose_name=_("uploaded at"),
|
|
)
|
|
|
|
class Meta:
|
|
verbose_name = _("document")
|
|
verbose_name_plural = _("documents")
|
|
|
|
|
|
class Authorization(Document):
|
|
user = models.ForeignKey(
|
|
TFJMUser,
|
|
on_delete=models.CASCADE,
|
|
related_name="authorizations",
|
|
verbose_name=_("user"),
|
|
)
|
|
|
|
type = models.CharField(
|
|
max_length=32,
|
|
choices=[
|
|
("parental_consent", _("Parental consent")),
|
|
("photo_consent", _("Photo consent")),
|
|
("sanitary_plug", _("Sanitary plug")),
|
|
("scholarship", _("Scholarship")),
|
|
],
|
|
verbose_name=_("type"),
|
|
)
|
|
|
|
class Meta:
|
|
verbose_name = _("authorization")
|
|
verbose_name_plural = _("authorizations")
|
|
|
|
def __str__(self):
|
|
return _("{authorization} for user {user}").format(authorization=self.type, user=str(self.user))
|
|
|
|
|
|
class MotivationLetter(Document):
|
|
team = models.ForeignKey(
|
|
Team,
|
|
on_delete=models.CASCADE,
|
|
related_name="motivation_letters",
|
|
verbose_name=_("team"),
|
|
)
|
|
|
|
class Meta:
|
|
verbose_name = _("motivation letter")
|
|
verbose_name_plural = _("motivation letters")
|
|
|
|
def __str__(self):
|
|
return _("Motivation letter of team {team} ({trigram})").format(team=self.team.name, trigram=self.team.trigram)
|
|
|
|
|
|
class Solution(Document):
|
|
team = models.ForeignKey(
|
|
Team,
|
|
on_delete=models.CASCADE,
|
|
related_name="solutions",
|
|
verbose_name=_("team"),
|
|
)
|
|
|
|
problem = models.PositiveSmallIntegerField(
|
|
verbose_name=_("problem"),
|
|
)
|
|
|
|
def save(self, **kwargs):
|
|
self.type = "solution"
|
|
super().save(**kwargs)
|
|
|
|
class Meta:
|
|
verbose_name = _("solution")
|
|
verbose_name_plural = _("solutions")
|
|
|
|
def __str__(self):
|
|
return _("Solution of team {trigram} for problem {problem}")\
|
|
.format(trigram=self.team.trigram, problem=self.problem)
|
|
|
|
|
|
class Synthesis(Document):
|
|
team = models.ForeignKey(
|
|
Team,
|
|
on_delete=models.CASCADE,
|
|
related_name="syntheses",
|
|
verbose_name=_("team"),
|
|
)
|
|
|
|
dest = models.CharField(
|
|
max_length=16,
|
|
choices=[
|
|
("defender", _("Defender")),
|
|
("opponent", _("Opponent")),
|
|
("rapporteur", _("Rapporteur")),
|
|
],
|
|
verbose_name=_("dest"),
|
|
)
|
|
|
|
def save(self, **kwargs):
|
|
self.type = "synthesis"
|
|
super().save(**kwargs)
|
|
|
|
class Meta:
|
|
verbose_name = _("synthesis")
|
|
verbose_name_plural = _("syntheses")
|
|
|
|
def __str__(self):
|
|
return _("Synthesis of team {trigram} that is {dest} for problem {problem}")\
|
|
.format(trigram=self.team.trigram, dest=self.dest, problem=self.problem)
|