From 14a1c6ba1f272060376f74762cbc2566e4952c04 Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Tue, 11 Jun 2024 23:40:00 +0200 Subject: [PATCH] add animation type tournament and handle the option to hide the points earned --- ..._tournament_hide_points_earned_and_more.py | 33 +++++++++++++++++++ tournaments/models/enums.py | 3 ++ tournaments/models/tournament.py | 13 ++++++-- .../tournaments/group_stage_cell.html | 6 +++- .../templates/tournaments/match_cell.html | 2 +- .../templates/tournaments/ranking_row.html | 6 +++- .../templates/tournaments/team_row.html | 2 ++ 7 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 tournaments/migrations/0068_tournament_hide_points_earned_and_more.py diff --git a/tournaments/migrations/0068_tournament_hide_points_earned_and_more.py b/tournaments/migrations/0068_tournament_hide_points_earned_and_more.py new file mode 100644 index 0000000..afcf3a4 --- /dev/null +++ b/tournaments/migrations/0068_tournament_hide_points_earned_and_more.py @@ -0,0 +1,33 @@ +# Generated by Django 4.2.11 on 2024-06-11 16:22 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('tournaments', '0067_alter_customuser_email'), + ] + + operations = [ + migrations.AddField( + model_name='tournament', + name='hide_points_earned', + field=models.BooleanField(default=False), + ), + migrations.AlterField( + model_name='tournament', + name='federal_age_category', + field=models.IntegerField(choices=[(0, 'Aucune'), (120, 'A11_12'), (140, 'A13_14'), (160, 'A15_16'), (180, 'A17_18'), (200, 'SENIOR'), (450, 'A45'), (550, 'A55')], default=200), + ), + migrations.AlterField( + model_name='tournament', + name='federal_category', + field=models.IntegerField(choices=[(0, 'Homme'), (1, 'Femme'), (2, 'Mixte'), (3, 'Aucune')], default=0), + ), + migrations.AlterField( + model_name='tournament', + name='federal_level_category', + field=models.IntegerField(choices=[(0, 'Animation'), (25, 'P25'), (100, 'P100'), (250, 'P250'), (500, 'P500'), (1000, 'P1000'), (1500, 'P1500'), (2000, 'P2000')], default=100), + ), + ] diff --git a/tournaments/models/enums.py b/tournaments/models/enums.py index 20bf56c..78a335a 100644 --- a/tournaments/models/enums.py +++ b/tournaments/models/enums.py @@ -11,8 +11,10 @@ class FederalCategory(models.IntegerChoices): MEN = 0, 'Homme' WOMEN = 1, 'Femme' MIXED = 2, 'Mixte' + UNLISTED = 3, '' class FederalLevelCategory(models.IntegerChoices): + UNLISTED = 0, 'Animation' P25 = 25, 'P25' P100 = 100, 'P100' P250 = 250, 'P250' @@ -22,6 +24,7 @@ class FederalLevelCategory(models.IntegerChoices): P2000 = 2000, 'P2000' class FederalAgeCategory(models.IntegerChoices): + UNLISTED = 0, '' A11_12 = 120, 'A11_12' A13_14 = 140, 'A13_14' A15_16 = 160, 'A15_16' diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 132dd64..e7a821a 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -56,6 +56,7 @@ class Tournament(models.Model): should_verify_bracket = models.BooleanField(default=False) should_verify_group_stage = models.BooleanField(default=False) publish_tournament = models.BooleanField(default=False) + hide_points_earned = models.BooleanField(default=False) def __str__(self): if self.name: @@ -130,7 +131,7 @@ class Tournament(models.Model): teams = self.teams() if self.supposedly_in_progress() or self.end_date is not None: - teams = [t for t in teams if t.stage is not "Attente"] + teams = [t for t in teams if t.stage != "Attente"] if teams is not None and len(teams) > 0: word = "équipe" if len(teams) > 1: @@ -506,7 +507,7 @@ class Tournament(models.Model): first_group_stage_start_date = self.group_stage_start_date() if first_group_stage_start_date is None: - return False + return datetime.now().date() >= self.start_date.date() group_stage_start_date = self.getEightAm(first_group_stage_start_date) @@ -536,7 +537,7 @@ class Tournament(models.Model): first_match_start_date = self.first_match_start_date(bracket_matches) if first_match_start_date is None: - return False + return datetime.now().date() >= self.start_date.date() bracket_start_date = self.getEightAm(first_match_start_date) if bracket_start_date < self.start_date: @@ -567,6 +568,12 @@ class Tournament(models.Model): end = self.start_date + timedelta(days=self.day_duration) return self.start_date.replace(hour=0, minute=0) <= timezone.now() <= end + def display_points_earned(self): + return self.federal_level_category != FederalLevelCategory.UNLISTED and self.hide_points_earned is False + + def hide_weight(self): + return self.federal_level_category == FederalLevelCategory.UNLISTED + class MatchGroup: def __init__(self, name, matches): self.name = name diff --git a/tournaments/templates/tournaments/group_stage_cell.html b/tournaments/templates/tournaments/group_stage_cell.html index 2d1dbae..93733ac 100644 --- a/tournaments/templates/tournaments/group_stage_cell.html +++ b/tournaments/templates/tournaments/group_stage_cell.html @@ -22,7 +22,11 @@
{% if team.match_count == 0 %} -
{{ team.weight }}
+ {% if tournament.hide_weight %} +
+ {% else %} +
{{ team.weight }}
+ {% endif %} {% else %}
{{ team.wins_losses }}
diff --git a/tournaments/templates/tournaments/match_cell.html b/tournaments/templates/tournaments/match_cell.html index 06b9fc2..9f13c75 100644 --- a/tournaments/templates/tournaments/match_cell.html +++ b/tournaments/templates/tournaments/match_cell.html @@ -34,7 +34,7 @@ {% endif %}
- {% else %} + {% elif not tournament.hide_weight %} {{ team.weight }} {% endif %}
diff --git a/tournaments/templates/tournaments/ranking_row.html b/tournaments/templates/tournaments/ranking_row.html index f568638..fefd21a 100644 --- a/tournaments/templates/tournaments/ranking_row.html +++ b/tournaments/templates/tournaments/ranking_row.html @@ -9,5 +9,9 @@ {% endfor %} -
{{ ranking.points }}
+ {% if tournament.display_points_earned %} +
{{ ranking.points }}
+ {% else %} +
+ {% endif %} diff --git a/tournaments/templates/tournaments/team_row.html b/tournaments/templates/tournaments/team_row.html index d8320c4..38937eb 100644 --- a/tournaments/templates/tournaments/team_row.html +++ b/tournaments/templates/tournaments/team_row.html @@ -9,6 +9,8 @@ {% if tournament.hide_teams_weight %}
+ {% elif tournament.hide_weight %} +
{% else %}
{{ team.weight }}
{% endif %}