2020-04-29 02:06:02 +00:00
|
|
|
import os
|
2020-04-29 13:29:01 +00:00
|
|
|
from datetime import date
|
2020-04-29 02:06:02 +00:00
|
|
|
|
|
|
|
from django.db import models
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
|
|
|
|
|
|
|
|
class Tournament(models.Model):
|
|
|
|
name = models.CharField(
|
|
|
|
max_length=255,
|
|
|
|
verbose_name=_("name"),
|
|
|
|
)
|
|
|
|
|
|
|
|
organizers = models.ManyToManyField(
|
|
|
|
'member.TFJMUser',
|
|
|
|
related_name="organized_tournaments",
|
|
|
|
verbose_name=_("organizers"),
|
|
|
|
)
|
|
|
|
|
|
|
|
size = models.PositiveSmallIntegerField(
|
|
|
|
verbose_name=_("size"),
|
|
|
|
)
|
|
|
|
|
|
|
|
place = models.CharField(
|
|
|
|
max_length=255,
|
|
|
|
verbose_name=_("place"),
|
|
|
|
)
|
|
|
|
|
|
|
|
price = models.PositiveSmallIntegerField(
|
|
|
|
verbose_name=_("price"),
|
|
|
|
)
|
|
|
|
|
|
|
|
description = models.TextField(
|
|
|
|
verbose_name=_("description"),
|
|
|
|
)
|
|
|
|
|
|
|
|
date_start = models.DateField(
|
|
|
|
verbose_name=_("date start"),
|
|
|
|
)
|
|
|
|
|
|
|
|
date_end = models.DateField(
|
2020-04-29 14:59:59 +00:00
|
|
|
verbose_name=_("date end"),
|
2020-04-29 02:06:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
date_inscription = models.DateTimeField(
|
|
|
|
verbose_name=_("date of registration closing"),
|
|
|
|
)
|
|
|
|
|
|
|
|
date_solutions = models.DateTimeField(
|
|
|
|
verbose_name=_("date of maximal solution submission"),
|
|
|
|
)
|
|
|
|
|
|
|
|
date_syntheses = models.DateTimeField(
|
|
|
|
verbose_name=_("date of maximal syntheses submission"),
|
|
|
|
)
|
|
|
|
|
|
|
|
final = models.BooleanField(
|
|
|
|
verbose_name=_("final tournament"),
|
|
|
|
)
|
|
|
|
|
|
|
|
year = models.PositiveIntegerField(
|
2020-04-29 13:29:01 +00:00
|
|
|
default=os.getenv("TFJM_YEAR", date.today().year),
|
|
|
|
verbose_name=_("year"),
|
2020-04-29 02:06:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get_final(cls):
|
|
|
|
return cls.objects.get(year=os.getenv("TFJM_YEAR"), final=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _("tournament")
|
|
|
|
verbose_name_plural = _("tournaments")
|
|
|
|
|
2020-04-29 04:52:39 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2020-04-29 02:06:02 +00:00
|
|
|
|
|
|
|
class Team(models.Model):
|
|
|
|
name = models.CharField(
|
|
|
|
max_length=255,
|
|
|
|
verbose_name=_("name"),
|
|
|
|
)
|
|
|
|
|
|
|
|
trigram = models.CharField(
|
|
|
|
max_length=3,
|
|
|
|
verbose_name=_("trigram"),
|
|
|
|
)
|
|
|
|
|
|
|
|
tournament = models.ForeignKey(
|
|
|
|
Tournament,
|
|
|
|
on_delete=models.PROTECT,
|
2020-04-29 14:59:59 +00:00
|
|
|
related_name="teams",
|
2020-04-29 02:06:02 +00:00
|
|
|
verbose_name=_("tournament"),
|
|
|
|
)
|
|
|
|
|
|
|
|
inscription_date = models.DateTimeField(
|
|
|
|
auto_now_add=True,
|
|
|
|
verbose_name=_("inscription date"),
|
|
|
|
)
|
|
|
|
|
|
|
|
validation_status = models.CharField(
|
|
|
|
max_length=8,
|
|
|
|
choices=[
|
2020-04-29 14:26:52 +00:00
|
|
|
("0invalid", _("Registration not validated")),
|
|
|
|
("1waiting", _("Waiting for validation")),
|
2020-04-29 14:59:59 +00:00
|
|
|
("2valid", _("Registration validated")),
|
2020-04-29 02:06:02 +00:00
|
|
|
],
|
|
|
|
verbose_name=_("validation status"),
|
|
|
|
)
|
|
|
|
|
|
|
|
selected_for_final = models.BooleanField(
|
|
|
|
default=False,
|
|
|
|
verbose_name=_("selected for final"),
|
|
|
|
)
|
|
|
|
|
|
|
|
access_code = models.CharField(
|
|
|
|
max_length=6,
|
|
|
|
unique=True,
|
|
|
|
verbose_name=_("access code"),
|
|
|
|
)
|
|
|
|
|
|
|
|
year = models.PositiveIntegerField(
|
2020-04-29 13:29:01 +00:00
|
|
|
default=os.getenv("TFJM_YEAR", date.today().year),
|
2020-04-29 02:06:02 +00:00
|
|
|
verbose_name=_("year"),
|
|
|
|
)
|
|
|
|
|
2020-04-29 05:39:52 +00:00
|
|
|
@property
|
|
|
|
def valid(self):
|
|
|
|
return self.validation_status == "valid"
|
|
|
|
|
|
|
|
@property
|
|
|
|
def waiting(self):
|
|
|
|
return self.validation_status == "waiting"
|
|
|
|
|
|
|
|
@property
|
|
|
|
def invalid(self):
|
|
|
|
return self.validation_status == "invalid"
|
|
|
|
|
2020-04-29 02:06:02 +00:00
|
|
|
@property
|
|
|
|
def encadrants(self):
|
|
|
|
return self.users.filter(role="encadrant")
|
|
|
|
|
|
|
|
@property
|
|
|
|
def participants(self):
|
|
|
|
return self.users.filter(role="participant")
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _("team")
|
|
|
|
verbose_name_plural = _("teams")
|
|
|
|
unique_together = (('name', 'year',), ('trigram', 'year',),)
|
|
|
|
|
2020-04-29 04:52:39 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2020-04-29 02:06:02 +00:00
|
|
|
|
|
|
|
class Payment(models.Model):
|
|
|
|
user = models.OneToOneField(
|
|
|
|
'member.TFJMUser',
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
related_name="payment",
|
|
|
|
verbose_name=_("user"),
|
|
|
|
)
|
|
|
|
|
|
|
|
team = models.ForeignKey(
|
|
|
|
Team,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
related_name="payments",
|
|
|
|
verbose_name=_("team"),
|
|
|
|
)
|
|
|
|
|
|
|
|
method = models.CharField(
|
|
|
|
max_length=16,
|
|
|
|
choices=[
|
|
|
|
("not_paid", _("Not paid")),
|
|
|
|
("credit_card", _("Credit card")),
|
|
|
|
("check", _("Bank check")),
|
|
|
|
("transfer", _("Bank transfer")),
|
|
|
|
("cash", _("Cash")),
|
|
|
|
("scholarship", _("Scholarship")),
|
|
|
|
],
|
|
|
|
default="not_paid",
|
|
|
|
verbose_name=_("payment method"),
|
|
|
|
)
|
|
|
|
|
|
|
|
validation_status = models.CharField(
|
|
|
|
max_length=8,
|
|
|
|
choices=[
|
2020-04-29 14:26:52 +00:00
|
|
|
("0invalid", _("Registration not validated")),
|
|
|
|
("1waiting", _("Waiting for validation")),
|
|
|
|
("2valid", _("Registration validated")),
|
2020-04-29 02:06:02 +00:00
|
|
|
],
|
|
|
|
verbose_name=_("validation status"),
|
|
|
|
)
|
2020-04-29 02:51:25 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _("payment")
|
|
|
|
verbose_name_plural = _("payments")
|
2020-04-29 04:52:39 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return _("Payment of {user}").format(str(self.user))
|