mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-07-03 18:02:50 +02:00
Add Passage model
This commit is contained in:
@ -5,6 +5,7 @@ import os
|
||||
|
||||
from address.models import AddressField
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.validators import RegexValidator
|
||||
from django.db import models
|
||||
from django.db.models import Index
|
||||
@ -324,6 +325,59 @@ class Pool(models.Model):
|
||||
verbose_name_plural = _("pools")
|
||||
|
||||
|
||||
class Passage(models.Model):
|
||||
pool = models.ForeignKey(
|
||||
Pool,
|
||||
on_delete=models.CASCADE,
|
||||
verbose_name=_("pool"),
|
||||
related_name="passages",
|
||||
)
|
||||
|
||||
place = models.CharField(
|
||||
verbose_name=_("place"),
|
||||
max_length=255,
|
||||
help_text=_("Where the solution is presented?"),
|
||||
default="Non indiqué",
|
||||
)
|
||||
|
||||
defender = models.ForeignKey(
|
||||
Participation,
|
||||
on_delete=models.PROTECT,
|
||||
verbose_name=_("defender"),
|
||||
related_name="+",
|
||||
)
|
||||
|
||||
opponent = models.ForeignKey(
|
||||
Participation,
|
||||
on_delete=models.PROTECT,
|
||||
verbose_name=_("opponent"),
|
||||
related_name="+",
|
||||
)
|
||||
|
||||
reporter = models.ForeignKey(
|
||||
Participation,
|
||||
on_delete=models.PROTECT,
|
||||
verbose_name=_("reporter"),
|
||||
related_name="+",
|
||||
)
|
||||
|
||||
def clean(self):
|
||||
if self.defender not in self.pool.participations.all():
|
||||
raise ValidationError(_("Team {trigram} is not registered in the pool.")
|
||||
.format(trigram=self.defender.team.trigram))
|
||||
if self.opponent not in self.pool.participations.all():
|
||||
raise ValidationError(_("Team {trigram} is not registered in the pool.")
|
||||
.format(trigram=self.opponent.team.trigram))
|
||||
if self.reporter not in self.pool.participations.all():
|
||||
raise ValidationError(_("Team {trigram} is not registered in the pool.")
|
||||
.format(trigram=self.reporter.team.trigram))
|
||||
return super().clean()
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("passage")
|
||||
verbose_name_plural = _("passages")
|
||||
|
||||
|
||||
def get_solution_filename(instance, filename):
|
||||
return f"solutions/{instance.participation.team.trigram}_{instance.problem}" \
|
||||
+ ("final" if instance.final_solution else "")
|
||||
@ -378,11 +432,11 @@ class Synthesis(models.Model):
|
||||
verbose_name=_("participation"),
|
||||
)
|
||||
|
||||
pool = models.ForeignKey(
|
||||
Pool,
|
||||
passage = models.ForeignKey(
|
||||
Passage,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="syntheses",
|
||||
verbose_name=_("pool"),
|
||||
verbose_name=_("passage"),
|
||||
)
|
||||
|
||||
type = models.PositiveSmallIntegerField(
|
||||
@ -400,10 +454,7 @@ class Synthesis(models.Model):
|
||||
default="",
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return repr(self)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("synthesis")
|
||||
verbose_name_plural = _("syntheses")
|
||||
unique_together = (('participation', 'pool', 'type', ), )
|
||||
unique_together = (('participation', 'passage', 'type', ), )
|
||||
|
Reference in New Issue
Block a user