mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-06-21 07:58:26 +02:00
Add migrations for ETEAM
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
@ -0,0 +1,77 @@
|
||||
# Generated by Django 5.0.6 on 2024-06-13 08:53
|
||||
|
||||
import django.core.validators
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("participation", "0016_tournament_date_first_phase_and_more"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="passage",
|
||||
name="solution_number",
|
||||
field=models.PositiveSmallIntegerField(
|
||||
choices=[
|
||||
(1, "Problem #1"),
|
||||
(2, "Problem #2"),
|
||||
(3, "Problem #3"),
|
||||
(4, "Problem #4"),
|
||||
(5, "Problem #5"),
|
||||
(6, "Problem #6"),
|
||||
(7, "Problem #7"),
|
||||
(8, "Problem #8"),
|
||||
(9, "Problem #9"),
|
||||
(10, "Problem #10"),
|
||||
],
|
||||
verbose_name="defended solution",
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="pool",
|
||||
name="round",
|
||||
field=models.PositiveSmallIntegerField(
|
||||
choices=[(1, "Round 1"), (2, "Round 2"), (3, "Round 3")],
|
||||
verbose_name="round",
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="solution",
|
||||
name="problem",
|
||||
field=models.PositiveSmallIntegerField(
|
||||
choices=[
|
||||
(1, "Problem #1"),
|
||||
(2, "Problem #2"),
|
||||
(3, "Problem #3"),
|
||||
(4, "Problem #4"),
|
||||
(5, "Problem #5"),
|
||||
(6, "Problem #6"),
|
||||
(7, "Problem #7"),
|
||||
(8, "Problem #8"),
|
||||
(9, "Problem #9"),
|
||||
(10, "Problem #10"),
|
||||
],
|
||||
verbose_name="problem",
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="team",
|
||||
name="trigram",
|
||||
field=models.CharField(
|
||||
help_text="The code must be composed of 4 uppercase letters.",
|
||||
max_length=4,
|
||||
unique=True,
|
||||
validators=[
|
||||
django.core.validators.RegexValidator("^[A-Z]{3}[A-Z]*$"),
|
||||
django.core.validators.RegexValidator(
|
||||
"^(?!BIT$|CNO$|CRO$|CUL$|FTG$|FCK$|FUC$|FUK$|FYS$|HIV$|IST$|MST$|KKK$|KYS$|SEX$)",
|
||||
message="This team code is forbidden.",
|
||||
),
|
||||
],
|
||||
verbose_name="code",
|
||||
),
|
||||
),
|
||||
]
|
@ -38,13 +38,13 @@ class Team(models.Model):
|
||||
)
|
||||
|
||||
trigram = models.CharField(
|
||||
max_length=settings.TEAM_CODE_LENGTH,
|
||||
max_length=4,
|
||||
verbose_name=_("code"),
|
||||
help_text=format_lazy(_("The code must be composed of {nb_letters} uppercase letters."),
|
||||
nb_letters=settings.TEAM_CODE_LENGTH),
|
||||
unique=True,
|
||||
validators=[
|
||||
RegexValidator("^[A-Z]{" + str(settings.TEAM_CODE_LENGTH) + "}$"),
|
||||
RegexValidator("^[A-Z]{3}[A-Z]*$"),
|
||||
RegexValidator(fr"^(?!{'|'.join(f'{t}$' for t in settings.FORBIDDEN_TRIGRAMS)})",
|
||||
message=_("This team code is forbidden.")),
|
||||
],
|
||||
@ -236,6 +236,12 @@ class Team(models.Model):
|
||||
get_sympa_client().unsubscribe(self.email, "equipes-non-valides", False)
|
||||
get_sympa_client().delete_list(f"equipe-{self.trigram}")
|
||||
|
||||
def clean(self):
|
||||
if len(self.trigram) != settings.TEAM_CODE_LENGTH:
|
||||
raise ValidationError({'trigram': _("The team code must be composed of {nb_letters} uppercase letters.")},
|
||||
params={'nb_letters': settings.TEAM_CODE_LENGTH})
|
||||
return super().clean()
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.access_code:
|
||||
# if the team got created, generate the access code, create the contact mailing list
|
||||
|
Reference in New Issue
Block a user