diff --git a/tournaments/migrations/0094_playerregistration_captain.py b/tournaments/migrations/0094_playerregistration_captain.py
new file mode 100644
index 0000000..17d54e1
--- /dev/null
+++ b/tournaments/migrations/0094_playerregistration_captain.py
@@ -0,0 +1,18 @@
+# Generated by Django 4.2.11 on 2024-11-15 07:51
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('tournaments', '0093_drawlog_draw_type_and_more'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='playerregistration',
+ name='captain',
+ field=models.BooleanField(default=False),
+ ),
+ ]
diff --git a/tournaments/models/player_enums.py b/tournaments/models/player_enums.py
index 59c46a7..11ee89a 100644
--- a/tournaments/models/player_enums.py
+++ b/tournaments/models/player_enums.py
@@ -15,6 +15,7 @@ class PlayerPaymentType(models.IntegerChoices):
class PlayerDataSource(models.IntegerChoices):
FRENCH_FEDERATION = 0, 'French Federation'
BEACH_PADEL = 1, 'Beach Padel'
+ ONLINE_REGISTRATION = 2, 'Online Registration'
class PlayerSexType(models.IntegerChoices):
FEMALE = 0, 'Female'
diff --git a/tournaments/models/player_registration.py b/tournaments/models/player_registration.py
index b35badb..7e9e6ec 100644
--- a/tournaments/models/player_registration.py
+++ b/tournaments/models/player_registration.py
@@ -33,6 +33,7 @@ class PlayerRegistration(models.Model):
source = models.IntegerField(choices=PlayerDataSource.choices, null=True, blank=True)
has_arrived = models.BooleanField(default=False)
+ captain = models.BooleanField(default=False)
def __str__(self):
return self.name()
diff --git a/tournaments/models/team_registration.py b/tournaments/models/team_registration.py
index 78da28b..e1112da 100644
--- a/tournaments/models/team_registration.py
+++ b/tournaments/models/team_registration.py
@@ -57,6 +57,11 @@ class TeamRegistration(models.Model):
else:
return [pr.shortened_name() for pr in players]
+ @property
+ def players(self):
+ # Fetch related PlayerRegistration objects
+ return self.playerregistration_set.all().order_by('rank')
+
def player_names(self):
names = self.player_names_as_list()
str = " - ".join(names)
@@ -90,6 +95,10 @@ class TeamRegistration(models.Model):
else:
return "--"
+ def set_weight(self):
+ self.weight = self.playerregistration_set.aggregate(total_weight=models.Sum('rank'))['total_weight'] or 0
+ self.save() # Save the updated weight if necessary
+
def is_valid_for_summon(self):
return len(self.playerregistration_set.all()) > 0
diff --git a/tournaments/templates/register_tournament.html b/tournaments/templates/register_tournament.html
index c1021cb..af45377 100644
--- a/tournaments/templates/register_tournament.html
+++ b/tournaments/templates/register_tournament.html
@@ -29,12 +29,22 @@
+
+
+ Informations de contact
+
+
{{ team_form.as_p }}
{% if current_players %}
-
+
+
+ Constitution de votre équipe
+
+
+
{% for player in current_players %}
- {{ player.first_name }} {{ player.last_name }} ({{ player.licence_id }})
{% endfor %}
diff --git a/tournaments/templates/registration/profile.html b/tournaments/templates/registration/profile.html
index 81ef067..842435f 100644
--- a/tournaments/templates/registration/profile.html
+++ b/tournaments/templates/registration/profile.html
@@ -1,7 +1,7 @@
{% extends 'tournaments/base.html' %}
-{% block head_title %} {% endblock %}
-{% block first_title %}{% endblock %}
-{% block second_title %}{% endblock %}
+{% block head_title %} Mon Compte {% endblock %}
+{% block first_title %} Mon Compte Padel Club {% endblock %}
+{% block second_title %} Mes tournois {% endblock %}
{% block content %}
@@ -11,20 +11,41 @@
{% load tz %}
-
- {% if tournaments %}
-
Vos tournois, {{ user_name }}
-
+
Vos tournois à venir
-
- {% for tournament in tournaments %}
+ {% if upcoming_tournaments %}
+ {% for tournament in upcoming_tournaments %}
{% include 'tournaments/tournament_row.html' %}
{% endfor %}
-
+ {% else %}
+ Aucun tournoi à venir
+ {% endif %}
- {% endif %}
+
+
Vos tournois en cours
+
+ {% if running_tournaments %}
+ {% for tournament in running_tournaments %}
+ {% include 'tournaments/tournament_row.html' %}
+ {% endfor %}
+ {% else %}
+ Aucun tournoi en cours
+ {% endif %}
-
+
+
+
+
Vos tournois terminés
+
+ {% if ended_tournaments %}
+ {% for tournament in ended_tournaments %}
+ {% include 'tournaments/tournament_row.html' %}
+ {% endfor %}
+ {% else %}
+ Aucun tournoi terminé
+ {% endif %}
+
+
{% endblock %}
diff --git a/tournaments/templates/tournaments/base.html b/tournaments/templates/tournaments/base.html
index 99a1214..14cf3de 100644
--- a/tournaments/templates/tournaments/base.html
+++ b/tournaments/templates/tournaments/base.html
@@ -49,11 +49,7 @@
class="logo inline"
/>
- {% if user.is_authenticated %}
-
Bienvenue sur Padel Club, {{ user.username }}
- {% else %}
{% block first_title %}Page Title{% endblock %}
- {% endif %}
{% block second_title %}Page Title{% endblock %}
diff --git a/tournaments/templates/tournaments/tournament_info.html b/tournaments/templates/tournaments/tournament_info.html
index b36206a..fd03226 100644
--- a/tournaments/templates/tournaments/tournament_info.html
+++ b/tournaments/templates/tournaments/tournament_info.html
@@ -37,33 +37,50 @@
{{ tournament.event.creator.full_name }}
{% endif %}
-
+ {% if tournament.online_register_is_enabled and team is None %}
- {% if tournament.online_register_is_enabled %}
- Votre équipe
-
- {% if team %}
- {% for name in team.player_names_as_list %}
-
{{ name }}
- {% endfor %}
+ L'inscription en ligne est possible.
+
-
Inscrit le {{ team.registration_date }}
-
-
- Se désinscrire
-
- {% else %}
-
- S'inscrire
+
{% endif %}
- {% endif %}
+
+
+ {% if tournament.online_register_is_enabled and team %}
+ Votre équipe
+
+
+
+
+ {% for player in team.players %}
+
{{ player.name }}{%if player.captain %} (C){% endif %}
+ {% endfor %}
+
+
+
+
Inscrit le {{ team.registration_date }}
+
+
+ {% if is_captain %}
+
+ Se désinscrire
+
+ {% else %}
+
+
Vous n'êtes pas le capitaine de l'équipe, la désinscription en ligne n'est pas disponible. Veuillez contacter le JAP ou votre partenaire.
+
+ {% endif %}
+
+ {% endif %}
diff --git a/tournaments/utils/licence_validator.py b/tournaments/utils/licence_validator.py
index 9b096c9..2f00e8d 100644
--- a/tournaments/utils/licence_validator.py
+++ b/tournaments/utils/licence_validator.py
@@ -13,6 +13,10 @@ class LicenseValidator:
return match.group(0)
return 'licence invalide'
+ @property
+ def computed_licence_id(self) -> str:
+ return f"{self.stripped_license}{self.computed_license_key}"
+
@property
def computed_license_key(self) -> str:
stripped = self.stripped_license
diff --git a/tournaments/utils/player_search.py b/tournaments/utils/player_search.py
index b14d799..018c7ff 100644
--- a/tournaments/utils/player_search.py
+++ b/tournaments/utils/player_search.py
@@ -27,7 +27,8 @@ def get_player_name_from_csv(licence_id):
# Return first name and last name from the row (3rd and 4th columns)
first_name = row[3] # 4th column: first name
last_name = row[2] # 3rd column: last name
- return first_name, last_name
+ rank = row[1] # 3rd column: last name
+ return first_name, last_name, rank
# Return None if no match is found
- return None, None
+ return None, None, None
diff --git a/tournaments/views.py b/tournaments/views.py
index 1c52aea..7ddf151 100644
--- a/tournaments/views.py
+++ b/tournaments/views.py
@@ -9,6 +9,7 @@ from django.core.files.storage import default_storage
from django.core.files.base import ContentFile
from tournaments.models.device_token import DeviceToken
+from tournaments.models.player_enums import PlayerDataSource
from .models import Court, DateInterval, Club, Tournament, CustomUser, Event, Round, GroupStage, Match, TeamScore, TeamRegistration, PlayerRegistration, Purchase, FailedApiCall
from .models import TeamSummon
@@ -104,6 +105,7 @@ def tournament_info(request, tournament_id):
tournament = get_object_or_404(Tournament, pk=tournament_id)
registered_user = None
team_registration = None
+ is_captain = False
if request.user.is_authenticated:
# Assuming user's licence_id is stored in the user profile (e.g., request.user.licence_id)
@@ -119,11 +121,13 @@ def tournament_info(request, tournament_id):
# If the user is registered, retrieve their team registration
if registered_user:
+ is_captain = registered_user.captain
team_registration = registered_user.team_registration
return render(request, 'tournaments/tournament_info.html', {
'tournament': tournament,
'team': team_registration,
+ 'is_captain': is_captain
})
@@ -574,8 +578,19 @@ def profile(request):
teamregistration__playerregistration__licence_id__startswith=stripped_license
).distinct().order_by('-start_date')
+ # Current time
+ current_time = timezone.now()
+
+ # Separate tournaments into categories
+ upcoming_tournaments = tournaments.filter(start_date__gt=current_time)
+ running_tournaments = tournaments.filter(start_date__lte=current_time, end_date=None)
+ ended_tournaments = tournaments.filter(end_date__isnull=False)
+
return render(request, 'registration/profile.html', {
'tournaments': tournaments,
+ 'upcoming_tournaments': upcoming_tournaments,
+ 'running_tournaments': running_tournaments,
+ 'ended_tournaments': ended_tournaments,
'user_name': user.username
})
@@ -638,10 +653,11 @@ def register_tournament(request, tournament_id):
else:
if add_player_form.first_tournament is False:
# Retrieve player names from the CSV file
- first_name, last_name = get_player_name_from_csv(licence_id)
- if first_name and last_name:
+ first_name, last_name, rank = get_player_name_from_csv(licence_id)
+ if first_name and last_name and rank:
player_data['first_name'] = first_name
player_data['last_name'] = last_name
+ player_data['rank'] = rank
# If validation passes, add the player to the session without clearing previous ones
request.session['team_registration'].append(player_data)
request.session.modified = True # Ensure session is updated
@@ -656,17 +672,33 @@ def register_tournament(request, tournament_id):
tournament=tournament,
registration_date=timezone.now()
)
+
+ stripped_license = None
+ if 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
for player_data in request.session['team_registration']:
+ is_captain = False
+ player_licence_id = player_data['licence_id']
+ if player_licence_id is not None and stripped_license is not None:
+ if player_licence_id.startswith(stripped_license):
+ is_captain = True
+
player_registration = PlayerRegistration.objects.create(
team_registration=team_registration,
+ captain=is_captain,
+ source=PlayerDataSource.ONLINE_REGISTRATION,
first_name=player_data['first_name'],
last_name=player_data['last_name'],
+ rank = player_data.get('rank', 70000),
licence_id=player_data['licence_id'],
email = player_data.get('email', None),
phone_number = player_data.get('phone_number', None)
)
+ team_registration.set_weight()
+
request.session['team_registration'] = []
registration_successful = True
else:
@@ -688,6 +720,13 @@ def register_tournament(request, tournament_id):
'phone': request.user.phone,
'licence_id': request.user.licence_id,
}
+
+ first_name, last_name, rank = get_player_name_from_csv(request.user.licence_id)
+ if first_name and last_name and rank:
+ validator = LicenseValidator(request.user.licence_id)
+ player_data['licence_id'] = validator.computed_licence_id
+ player_data['rank'] = rank
+
request.session['team_registration'].insert(0, player_data) # Add them as the first player
request.session.modified = True # Ensure session is updated