From 79625aae38c574f36e78bd943a26d16c86ac4f4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zahradn=C3=ADk?= Date: Tue, 14 Oct 2025 21:21:06 +0200 Subject: [PATCH] add option to abbreviate names in public views --- .../bullet_admin/results/announce.html | 8 +++++++- bullet/competitions/factories/venues.py | 2 +- ...articipants_hidden_venue_abbreviate_names.py | 17 +++++++++++++++++ bullet/competitions/models/venues.py | 2 +- bullet/competitions/templates/teams/list.html | 8 +++++++- .../templates/problems/results/table.html | 8 +++++++- bullet/users/models/contestants.py | 15 +++++++++++++++ 7 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 bullet/competitions/migrations/0036_rename_participants_hidden_venue_abbreviate_names.py diff --git a/bullet/bullet_admin/templates/bullet_admin/results/announce.html b/bullet/bullet_admin/templates/bullet_admin/results/announce.html index d698e2a1..742bc2a0 100644 --- a/bullet/bullet_admin/templates/bullet_admin/results/announce.html +++ b/bullet/bullet_admin/templates/bullet_admin/results/announce.html @@ -28,7 +28,13 @@
{{ team.name }}
{% endif %} -
{{ team.contestants_names }}
+
+ {% if team.venue.abbreviate_names %} + {{ team.abbreviated_names }} + {% else %} + {{ team.contestants_names }} + {% endif %} +
{% squares result_row big=True %}
{{ result_row.solved_count }}
{% endif %} diff --git a/bullet/competitions/factories/venues.py b/bullet/competitions/factories/venues.py index a8506aea..0df1531d 100644 --- a/bullet/competitions/factories/venues.py +++ b/bullet/competitions/factories/venues.py @@ -24,5 +24,5 @@ class Meta: "random_elements", elements=[x[0] for x in settings.LANGUAGES] ) results_announced = factory.Faker("boolean") - participants_hidden = factory.Faker("boolean") + abbreviate_names = factory.Faker("boolean") email = factory.Faker("email") diff --git a/bullet/competitions/migrations/0036_rename_participants_hidden_venue_abbreviate_names.py b/bullet/competitions/migrations/0036_rename_participants_hidden_venue_abbreviate_names.py new file mode 100644 index 00000000..fa1da29f --- /dev/null +++ b/bullet/competitions/migrations/0036_rename_participants_hidden_venue_abbreviate_names.py @@ -0,0 +1,17 @@ +# Generated by Django 5.2.7 on 2025-10-14 19:13 + +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("competitions", "0035_auto_20250123_1932"), + ] + + operations = [ + migrations.RenameField( + model_name="venue", + old_name="participants_hidden", + new_name="abbreviate_names", + ), + ] diff --git a/bullet/competitions/models/venues.py b/bullet/competitions/models/venues.py index 8633a739..e6387add 100644 --- a/bullet/competitions/models/venues.py +++ b/bullet/competitions/models/venues.py @@ -106,7 +106,7 @@ class RegistrationFlowType(models.IntegerChoices): accepted_languages = ChoiceArrayField(LanguageField()) local_start = models.DateTimeField(null=True, blank=True) results_announced = models.BooleanField(default=False) # unused - participants_hidden = models.BooleanField(default=False) # unused + abbreviate_names = models.BooleanField(default=False) is_online = models.BooleanField(default=False) is_isolated = models.BooleanField(default=False) diff --git a/bullet/competitions/templates/teams/list.html b/bullet/competitions/templates/teams/list.html index a2983dd8..9879b8ec 100644 --- a/bullet/competitions/templates/teams/list.html +++ b/bullet/competitions/templates/teams/list.html @@ -66,7 +66,13 @@

{% for team in v.teams %}
{% inline_team_name team %} -
{{ team.contestants.all|join:", " }}
+
+ {% if v.venue.abbreviate_names %} + {{ team.abbreviated_names }} + {% else %} + {{ team.contestants_names }} + {% endif %} +
{% endfor %} diff --git a/bullet/problems/templates/problems/results/table.html b/bullet/problems/templates/problems/results/table.html index f823a569..70465ce5 100644 --- a/bullet/problems/templates/problems/results/table.html +++ b/bullet/problems/templates/problems/results/table.html @@ -42,7 +42,13 @@ {% endif %} {% if not hide_contestants %} -
{{ row.team.contestants.all|join:", " }}
+
+ {% if row.team.venue.abbreviate_names %} + {{ row.team.abbreviated_names }} + {% else %} + {{ row.team.contestants_names }} + {% endif %} +
{% endif %} diff --git a/bullet/users/models/contestants.py b/bullet/users/models/contestants.py index 1975509e..00314d47 100644 --- a/bullet/users/models/contestants.py +++ b/bullet/users/models/contestants.py @@ -150,6 +150,10 @@ def contact_phone_pretty(self): def contestants_names(self): return ", ".join([c.full_name for c in self.contestants.all()]) + @property + def abbreviated_names(self): + return ", ".join([c.abbreviated_name for c in self.contestants.all()]) + @property def id_display(self): return f"#{self.id:06d}" @@ -248,6 +252,7 @@ def to_export(self, str_only: bool = False): "contestants": self.contestants_names if str_only else [c.full_name for c in self.contestants.all()], + "abbreviated_contestants": self.abbreviated_names, "online_password": self.online_password, "rank_venue": self.rank_venue or "", "rank_country": self.rank_country or "", @@ -280,6 +285,16 @@ def __str__(self): name += f" ({self.grade.name})" return name + @property + def abbreviated_name(self): + parts = self.full_name.split() + if not parts: + return "" + if len(parts) == 1: + return parts[0] + + return f"{parts[0]} {parts[-1][0]}." + def get_spanish_upload(instance, filename): name, ext = os.path.splitext(filename)