114 lines
3.0 KiB
Python
114 lines
3.0 KiB
Python
from django.core.validators import RegexValidator
|
|
from django.db import models
|
|
from django.db.models import Index
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
|
|
class Team(models.Model):
|
|
name = models.CharField(
|
|
max_length=255,
|
|
verbose_name=_("name"),
|
|
unique=True,
|
|
)
|
|
|
|
trigram = models.CharField(
|
|
max_length=3,
|
|
verbose_name=_("trigram"),
|
|
help_text=_("The trigram must be composed of 3 uppercase letters."),
|
|
unique=True,
|
|
validators=[RegexValidator("[A-Z]{3}")],
|
|
)
|
|
|
|
access_code = models.CharField(
|
|
max_length=6,
|
|
verbose_name=_("access code"),
|
|
help_text=_("The access code let other people to join the team."),
|
|
)
|
|
|
|
def __str__(self):
|
|
return _("Team {name} ({trigram})").format(name=self.name, trigram=self.trigram)
|
|
|
|
class Meta:
|
|
verbose_name = _("team")
|
|
verbose_name_plural = _("teams")
|
|
indexes = [
|
|
Index(fields=("trigram", )),
|
|
]
|
|
|
|
|
|
class Participation(models.Model):
|
|
team = models.OneToOneField(
|
|
Team,
|
|
on_delete=models.CASCADE,
|
|
verbose_name=_("team"),
|
|
)
|
|
|
|
problem = models.IntegerField(
|
|
choices=[(i, _("Problem #{problem:d}").format(problem=i)) for i in range(1, 5)],
|
|
null=True,
|
|
default=None,
|
|
verbose_name=_("problem number"),
|
|
)
|
|
|
|
solution = models.ForeignKey(
|
|
"participation.Video",
|
|
on_delete=models.SET_NULL,
|
|
related_name="+",
|
|
null=True,
|
|
default=None,
|
|
verbose_name=_("solution video"),
|
|
)
|
|
|
|
received_participation = models.OneToOneField(
|
|
"participation.Participation",
|
|
on_delete=models.PROTECT,
|
|
related_name="sent_participation",
|
|
null=True,
|
|
default=None,
|
|
verbose_name=_("received participation"),
|
|
)
|
|
|
|
synthesis = models.ForeignKey(
|
|
"participation.Video",
|
|
on_delete=models.SET_NULL,
|
|
related_name="+",
|
|
null=True,
|
|
default=None,
|
|
verbose_name=_("synthesis video"),
|
|
)
|
|
|
|
def __str__(self):
|
|
return _("Participation of the team {name} ({trigram})").format(name=self.team.name, trigram=self.team.trigram)
|
|
|
|
class Meta:
|
|
verbose_name = _("participation")
|
|
verbose_name_plural = _("participations")
|
|
|
|
|
|
class Video(models.Model):
|
|
participation = models.ForeignKey(
|
|
"participation.Participation",
|
|
on_delete=models.CASCADE,
|
|
verbose_name=_("participation"),
|
|
)
|
|
|
|
link = models.URLField(
|
|
verbose_name=_("link"),
|
|
help_text=_("The full video link."),
|
|
)
|
|
|
|
valid = models.BooleanField(
|
|
null=True,
|
|
default=None,
|
|
verbose_name=_("valid"),
|
|
help_text=_("The video got the validation of the administrators."),
|
|
)
|
|
|
|
def __str__(self):
|
|
return _("Video of team {name} ({trigram})")\
|
|
.format(name=self.participation.team.name, trigram = self.participation.team.trigram)
|
|
|
|
class Meta:
|
|
verbose_name = _("video")
|
|
verbose_name_plural = _("videos")
|