From b885afa69db990977e57549da628069ed8e08bbd Mon Sep 17 00:00:00 2001 From: Raz Date: Fri, 29 Nov 2024 15:53:52 +0100 Subject: [PATCH] improve online reg --- tournaments/forms.py | 2 +- .../migrations/0095_merge_20241129_1243.py | 14 +++++++ ...tournament_account_is_required_and_more.py | 38 +++++++++++++++++++ ..._display_entry_fee_information_and_more.py | 23 +++++++++++ tournaments/models/team_score.py | 18 ++++++++- tournaments/models/tournament.py | 6 +++ tournaments/static/tournaments/css/style.css | 5 +++ .../templates/register_tournament.html | 21 +++++----- .../templates/tournaments/match_cell.html | 7 +++- .../tournaments/tournament_info.html | 16 +++++++- tournaments/views.py | 20 +++++----- 11 files changed, 145 insertions(+), 25 deletions(-) create mode 100644 tournaments/migrations/0095_merge_20241129_1243.py create mode 100644 tournaments/migrations/0096_tournament_account_is_required_and_more.py create mode 100644 tournaments/migrations/0097_tournament_display_entry_fee_information_and_more.py diff --git a/tournaments/forms.py b/tournaments/forms.py index 5b1244a..18fe5a6 100644 --- a/tournaments/forms.py +++ b/tournaments/forms.py @@ -68,7 +68,7 @@ class TournamentRegistrationForm(forms.Form): return mobile_number class AddPlayerForm(forms.Form): - licence_id = forms.CharField(label='Numéro de license (avec la lettre)', max_length=20) + licence_id = forms.CharField(label='Numéro de license (avec la lettre)', max_length=20, required=False) first_name = forms.CharField(label='Prénom', min_length=2, max_length=50, required=False) last_name = forms.CharField(label='Nom', min_length=2, max_length=50, required=False) first_tournament = False diff --git a/tournaments/migrations/0095_merge_20241129_1243.py b/tournaments/migrations/0095_merge_20241129_1243.py new file mode 100644 index 0000000..e153763 --- /dev/null +++ b/tournaments/migrations/0095_merge_20241129_1243.py @@ -0,0 +1,14 @@ +# Generated by Django 4.2.11 on 2024-11-29 11:43 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('tournaments', '0094_alter_customuser_bracket_match_format_preference_and_more'), + ('tournaments', '0094_playerregistration_captain'), + ] + + operations = [ + ] diff --git a/tournaments/migrations/0096_tournament_account_is_required_and_more.py b/tournaments/migrations/0096_tournament_account_is_required_and_more.py new file mode 100644 index 0000000..2bdad7a --- /dev/null +++ b/tournaments/migrations/0096_tournament_account_is_required_and_more.py @@ -0,0 +1,38 @@ +# Generated by Django 4.2.11 on 2024-11-29 11:43 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('tournaments', '0095_merge_20241129_1243'), + ] + + operations = [ + migrations.AddField( + model_name='tournament', + name='account_is_required', + field=models.BooleanField(default=True), + ), + migrations.AddField( + model_name='tournament', + name='license_is_required', + field=models.BooleanField(default=True), + ), + migrations.AddField( + model_name='tournament', + name='maximum_player_per_team', + field=models.IntegerField(default=2), + ), + migrations.AddField( + model_name='tournament', + name='minimum_player_per_team', + field=models.IntegerField(default=2), + ), + migrations.AlterField( + model_name='playerregistration', + name='source', + field=models.IntegerField(blank=True, choices=[(0, 'French Federation'), (1, 'Beach Padel'), (2, 'Online Registration')], null=True), + ), + ] diff --git a/tournaments/migrations/0097_tournament_display_entry_fee_information_and_more.py b/tournaments/migrations/0097_tournament_display_entry_fee_information_and_more.py new file mode 100644 index 0000000..629930d --- /dev/null +++ b/tournaments/migrations/0097_tournament_display_entry_fee_information_and_more.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.11 on 2024-11-29 13:42 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('tournaments', '0096_tournament_account_is_required_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='tournament', + name='display_entry_fee_information', + field=models.BooleanField(default=False), + ), + migrations.AddField( + model_name='tournament', + name='information', + field=models.CharField(blank=True, max_length=4000, null=True), + ), + ] diff --git a/tournaments/models/team_score.py b/tournaments/models/team_score.py index 3c510b2..3549566 100644 --- a/tournaments/models/team_score.py +++ b/tournaments/models/team_score.py @@ -40,10 +40,24 @@ class TeamScore(models.Model): def scores(self): if self.score: - return [int(x) for x in self.score.split(',')] + return [ + int(x.split('-')[0]) # Extract the integer part before the hyphen + for x in self.score.split(',') # Split by commas for multiple scores + ] else: return [] + def parsed_scores(self): + if self.score: + return [ + { + 'main': int(x.split('-')[0]), # Main score + 'tiebreak': x.split('-')[1] if '-' in x else None # Tiebreak + } + for x in self.score.split(',') + ] + return [] + def scores_array(self): if self.score: return [x for x in self.score.split(',')] @@ -79,7 +93,7 @@ class TeamScore(models.Model): weight= None is_winner = False names = self.shortened_team_names() - scores = self.scores_array() + scores = self.parsed_scores() walk_out = self.walk_out from .match import Team # Import Team only when needed team = Team(image, names, scores, weight, is_winner, walk_out) diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 9a2876f..36e88c2 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -65,6 +65,12 @@ class Tournament(models.Model): loser_bracket_mode = models.IntegerField(default=0) initial_seed_round = models.IntegerField(default=0) initial_seed_count = models.IntegerField(default=0) + account_is_required = models.BooleanField(default=True) + license_is_required = models.BooleanField(default=True) + minimum_player_per_team = models.IntegerField(default=2) + maximum_player_per_team = models.IntegerField(default=2) + information = models.CharField(max_length=4000, null=True, blank=True) + display_entry_fee_information = models.BooleanField(default=False) def __str__(self): if self.name: diff --git a/tournaments/static/tournaments/css/style.css b/tournaments/static/tournaments/css/style.css index 51e96dd..a3b5bea 100644 --- a/tournaments/static/tournaments/css/style.css +++ b/tournaments/static/tournaments/css/style.css @@ -700,3 +700,8 @@ h-margin { color: #f39200; /* Optional: Define a hover color */ text-decoration: none; /* Optional: Remove underline on hover */ } + +.sup { + font-size: x-small; + vertical-align: super; +} diff --git a/tournaments/templates/register_tournament.html b/tournaments/templates/register_tournament.html index fd477dc..0a53dbf 100644 --- a/tournaments/templates/register_tournament.html +++ b/tournaments/templates/register_tournament.html @@ -46,7 +46,7 @@

{% endif %} @@ -55,16 +55,18 @@ {% if current_players|length < 2 %}
- {% if user_without_licence %} + {% if user_without_licence and tournament.license_is_required %}
Une licence est obligatoire pour vous inscrire :
{% endif %} + {% if tournament.license_is_required %} {{ add_player_form.licence_id.label_tag }} {{ add_player_form.licence_id }} - {% if add_player_form.first_tournament or user_without_licence %} - {% if not user_without_licence %} + {% endif %} + {% if add_player_form.first_tournament or user_without_licence or tournament.license_is_required is False %} + {% if not user_without_licence and tournament.license_is_required is True %}
Précisez les informations du joueur :
@@ -73,6 +75,10 @@ {{ add_player_form.first_name }} {{ add_player_form.last_name.label_tag }} {{ add_player_form.last_name }} + {% if tournament.license_is_required is False %} + {{ add_player_form.licence_id.label_tag }} + {{ add_player_form.licence_id }} + {% endif %} {% endif %} {% endif %} - {% if registration_successful %} -

Registration was successful! Your team and players have been registered.

- {% endif %} - - {% for message in messages %}
{{ message }}
{% endfor %} diff --git a/tournaments/templates/tournaments/match_cell.html b/tournaments/templates/tournaments/match_cell.html index cbed073..231bedb 100644 --- a/tournaments/templates/tournaments/match_cell.html +++ b/tournaments/templates/tournaments/match_cell.html @@ -28,7 +28,12 @@ {% if match.should_show_scores %}
{% for score in team.scores %} - {{ score }} + + {{ score.main }} + {% if score.tiebreak %} + {{ score.tiebreak }} + {% endif %} + {% endfor %}
{% elif match.has_walk_out %} diff --git a/tournaments/templates/tournaments/tournament_info.html b/tournaments/templates/tournaments/tournament_info.html index ab8b2f2..8f5ca89 100644 --- a/tournaments/templates/tournaments/tournament_info.html +++ b/tournaments/templates/tournaments/tournament_info.html @@ -37,6 +37,20 @@
{{ tournament.event.creator.full_name }}

{% endif %} + + {% if tournament.information %} +

+

Infos
+
{{ tournament.information }}
+

+ {% endif %} + + {% if tournament.display_entry_fee_information %} +

+

{{ tournament.entry_fee_information }}
+

+ {% endif %} + {% if tournament.online_register_is_enabled and team is None %} @@ -46,7 +60,7 @@

- {% if user.is_authenticated and user.is_active %} + {% if tournament.account_is_required is False or user.is_authenticated and user.is_active %}

diff --git a/tournaments/views.py b/tournaments/views.py index e1beefa..63a5476 100644 --- a/tournaments/views.py +++ b/tournaments/views.py @@ -613,10 +613,10 @@ def register_tournament(request, tournament_id): player_data = add_player_form.cleaned_data # Validate the license ID before adding the player licence_id = player_data['licence_id'].upper() - # Instantiate your custom validator and validate the license ID + validator = LicenseValidator(licence_id) - if validator.validate_license() is False: + if validator.validate_license() is False and tournament.license_is_required is True: messages.error(request, f"Le numéro de licence est invalide, la lettre ne correspond pas. {validator.computed_license_key}") return render(request, 'register_tournament.html', { 'team_form': team_form, @@ -629,7 +629,7 @@ def register_tournament(request, tournament_id): # Check if the player with the same licence_id already exists in the session existing_players = [player['licence_id'] for player in request.session['team_registration']] - if licence_id in existing_players: + if validator.validate_license() and licence_id in existing_players: messages.error(request, "Ce joueur est déjà dans l'équipe.") return render(request, 'register_tournament.html', { 'team_form': team_form, @@ -642,7 +642,7 @@ def register_tournament(request, tournament_id): else: # Check if a PlayerRegistration with the same licence_id already exists in the database stripped_license = validator.stripped_license - if validate_license_id(stripped_license, tournament): + if validator.validate_license() and validate_license_id(stripped_license, tournament) and tournament.license_is_required is True: messages.error(request, "Un joueur avec ce numéro de licence est déjà inscrit dans une équipe.") return render(request, 'register_tournament.html', { 'team_form': team_form, @@ -655,7 +655,7 @@ def register_tournament(request, tournament_id): elif add_player_form.names_is_valid(): add_player_form = AddPlayerForm() request.session['team_registration'].append(player_data) - if request.user.licence_id is None: + if request.user.is_authenticated and request.user.licence_id is None: request.session['user_without_licence'] = False request.user.licence_id = validator.computed_licence_id request.user.save() @@ -688,7 +688,7 @@ def register_tournament(request, tournament_id): ) stripped_license = None - if request.user.licence_id is not None: + if request.user.is_authenticated and request.user.licence_id is not None: stripped_license = LicenseValidator(request.user.licence_id).stripped_license # Create PlayerRegistration objects for each player in the session @@ -701,7 +701,7 @@ def register_tournament(request, tournament_id): is_woman = player_data.get('is_woman', False) - rank = player_data['rank'] + rank = player_data.get('rank', 0) computed_rank = None sex = PlayerSexType.MALE if is_woman is None: @@ -731,8 +731,8 @@ def register_tournament(request, tournament_id): rank = rank, computed_rank = computed_rank, licence_id=player_data['licence_id'], - email = player_data.get('email', None), - phone_number = player_data.get('phone_number', None) + email = team_form.cleaned_data['email'], + phone_number = team_form.cleaned_data['mobile_number'] ) team_registration.set_weight() @@ -743,12 +743,12 @@ def register_tournament(request, tournament_id): add_player_form = AddPlayerForm() request.session['team_registration'] = [] - user_licence_id = request.user.licence_id initial_data = {} player_data = {} # Add the authenticated user to the session as the first player if not already added if request.user.is_authenticated: + user_licence_id = request.user.licence_id initial_data = { 'email': request.user.email, 'phone': request.user.phone,