add my account view

online_registration
Raz 12 months ago
parent 64eba2a965
commit ed0dfedd61
  1. 18
      tournaments/migrations/0094_playerregistration_captain.py
  2. 1
      tournaments/models/player_enums.py
  3. 1
      tournaments/models/player_registration.py
  4. 9
      tournaments/models/team_registration.py
  5. 12
      tournaments/templates/register_tournament.html
  6. 45
      tournaments/templates/registration/profile.html
  7. 4
      tournaments/templates/tournaments/base.html
  8. 51
      tournaments/templates/tournaments/tournament_info.html
  9. 4
      tournaments/utils/licence_validator.py
  10. 5
      tournaments/utils/player_search.py
  11. 43
      tournaments/views.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),
),
]

@ -15,6 +15,7 @@ class PlayerPaymentType(models.IntegerChoices):
class PlayerDataSource(models.IntegerChoices): class PlayerDataSource(models.IntegerChoices):
FRENCH_FEDERATION = 0, 'French Federation' FRENCH_FEDERATION = 0, 'French Federation'
BEACH_PADEL = 1, 'Beach Padel' BEACH_PADEL = 1, 'Beach Padel'
ONLINE_REGISTRATION = 2, 'Online Registration'
class PlayerSexType(models.IntegerChoices): class PlayerSexType(models.IntegerChoices):
FEMALE = 0, 'Female' FEMALE = 0, 'Female'

@ -33,6 +33,7 @@ class PlayerRegistration(models.Model):
source = models.IntegerField(choices=PlayerDataSource.choices, null=True, blank=True) source = models.IntegerField(choices=PlayerDataSource.choices, null=True, blank=True)
has_arrived = models.BooleanField(default=False) has_arrived = models.BooleanField(default=False)
captain = models.BooleanField(default=False)
def __str__(self): def __str__(self):
return self.name() return self.name()

@ -57,6 +57,11 @@ class TeamRegistration(models.Model):
else: else:
return [pr.shortened_name() for pr in players] 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): def player_names(self):
names = self.player_names_as_list() names = self.player_names_as_list()
str = " - ".join(names) str = " - ".join(names)
@ -90,6 +95,10 @@ class TeamRegistration(models.Model):
else: else:
return "--" 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): def is_valid_for_summon(self):
return len(self.playerregistration_set.all()) > 0 return len(self.playerregistration_set.all()) > 0

@ -29,12 +29,22 @@
<!-- Team Registration Form --> <!-- Team Registration Form -->
<div> <div>
<p>
<div class="semibold">
Informations de contact
</div>
</p>
{{ team_form.as_p }} <!-- Render team registration form fields here --> {{ team_form.as_p }} <!-- Render team registration form fields here -->
</div> </div>
<!-- Show players added to the team only if there are players added --> <!-- Show players added to the team only if there are players added -->
{% if current_players %} {% if current_players %}
<ul> <p>
<div class="semibold">
Constitution de votre équipe
</div>
</p>
<ul>
{% for player in current_players %} {% for player in current_players %}
<li>{{ player.first_name }} {{ player.last_name }} ({{ player.licence_id }})</li> <li>{{ player.first_name }} {{ player.last_name }} ({{ player.licence_id }})</li>
{% endfor %} {% endfor %}

@ -1,7 +1,7 @@
{% extends 'tournaments/base.html' %} {% extends 'tournaments/base.html' %}
{% block head_title %} {% endblock %} {% block head_title %} Mon Compte {% endblock %}
{% block first_title %}{% endblock %} {% block first_title %} Mon Compte Padel Club {% endblock %}
{% block second_title %}{% endblock %} {% block second_title %} Mes tournois {% endblock %}
{% block content %} {% block content %}
@ -11,20 +11,41 @@
{% load tz %} {% load tz %}
<div class="grid-x"> <div class="grid-x">
{% if tournaments %}
<div class="cell medium-6 large-6 topblock my-block"> <div class="cell medium-6 large-6 topblock my-block">
<h1 class="club my-block topmargin20">Vos tournois, {{ user_name }}</h1 > <h1 class="club my-block">Vos tournois à venir</h1 >
<div class="bubble"> <div class="bubble">
{% if upcoming_tournaments %}
{% for tournament in tournaments %} {% for tournament in upcoming_tournaments %}
{% include 'tournaments/tournament_row.html' %} {% include 'tournaments/tournament_row.html' %}
{% endfor %} {% endfor %}
{% else %}
Aucun tournoi à venir
{% endif %}
</div> </div>
</div> </div>
{% endif %} <div class="cell medium-6 large-6 topblock my-block">
<h1 class="club my-block">Vos tournois en cours</h1 >
<div class="bubble">
{% if running_tournaments %}
{% for tournament in running_tournaments %}
{% include 'tournaments/tournament_row.html' %}
{% endfor %}
{% else %}
Aucun tournoi en cours
{% endif %}
</div> </div>
</div>
<div class="cell medium-6 large-6 topblock my-block">
<h1 class="club my-block">Vos tournois terminés</h1 >
<div class="bubble">
{% if ended_tournaments %}
{% for tournament in ended_tournaments %}
{% include 'tournaments/tournament_row.html' %}
{% endfor %}
{% else %}
Aucun tournoi terminé
{% endif %}
</div>
</div>
{% endblock %} {% endblock %}

@ -49,11 +49,7 @@
class="logo inline" class="logo inline"
/> />
<div class="inline padding-left"> <div class="inline padding-left">
{% if user.is_authenticated %}
<h1 class="club">Bienvenue sur Padel Club, {{ user.username }}</h1>
{% else %}
<h1 class="club">{% block first_title %}Page Title{% endblock %}</h1> <h1 class="club">{% block first_title %}Page Title{% endblock %}</h1>
{% endif %}
<h1 class="event">{% block second_title %}Page Title{% endblock %}</h1> <h1 class="event">{% block second_title %}Page Title{% endblock %}</h1>
</div> </div>
</a> </a>

@ -37,33 +37,50 @@
<div>{{ tournament.event.creator.full_name }}</div> <div>{{ tournament.event.creator.full_name }}</div>
</p> </p>
{% endif %} {% endif %}
</div> {% if tournament.online_register_is_enabled and team is None %}
{% if tournament.online_register_is_enabled %}
<h1 class="club my-block topmargin20">Votre équipe</h1 >
<div class="bubble">
{% if team %}
<p> <p>
<div class="semibold"> <div class="semibold">
{% for name in team.player_names_as_list %} L'inscription en ligne est possible.
<div>{{ name }}</div>
{% endfor %}
</div> </div>
</p> </p>
<p> <p>
<div>Inscrit le {{ team.registration_date }}</div> <div>
</p> <a href="{% url 'register_tournament' tournament.id %}?reset=true" class="button">S'inscrire</a>
<p> </div>
<a href="{% url 'unregister_tournament' tournament.id %}" class="button danger">Se désinscrire</a>
</p>
{% else %}
<p>
<a href="{% url 'register_tournament' tournament.id %}?reset=true" class="button">S'inscrire</a>
</p> </p>
{% endif %} {% endif %}
{% endif %}
</div> </div>
{% if tournament.online_register_is_enabled and team %}
<h1 class="club my-block topmargin20">Votre équipe</h1 >
<div class="bubble">
<p>
<div class="semibold">
{% for player in team.players %}
<div>{{ player.name }}{%if player.captain %} (C){% endif %}</div>
{% endfor %}
</div>
</p>
<p>
<div>Inscrit le {{ team.registration_date }}</div>
</p>
{% if is_captain %}
<p>
<a href="{% url 'unregister_tournament' tournament.id %}" class="button danger">Se désinscrire</a>
</p>
{% else %}
<p>
<div>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.</div>
</p>
{% endif %}
</div>
{% endif %}
</div> </div>
</div> </div>

@ -13,6 +13,10 @@ class LicenseValidator:
return match.group(0) return match.group(0)
return 'licence invalide' return 'licence invalide'
@property
def computed_licence_id(self) -> str:
return f"{self.stripped_license}{self.computed_license_key}"
@property @property
def computed_license_key(self) -> str: def computed_license_key(self) -> str:
stripped = self.stripped_license stripped = self.stripped_license

@ -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) # Return first name and last name from the row (3rd and 4th columns)
first_name = row[3] # 4th column: first name first_name = row[3] # 4th column: first name
last_name = row[2] # 3rd column: last 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 if no match is found
return None, None return None, None, None

@ -9,6 +9,7 @@ from django.core.files.storage import default_storage
from django.core.files.base import ContentFile from django.core.files.base import ContentFile
from tournaments.models.device_token import DeviceToken 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 Court, DateInterval, Club, Tournament, CustomUser, Event, Round, GroupStage, Match, TeamScore, TeamRegistration, PlayerRegistration, Purchase, FailedApiCall
from .models import TeamSummon from .models import TeamSummon
@ -104,6 +105,7 @@ def tournament_info(request, tournament_id):
tournament = get_object_or_404(Tournament, pk=tournament_id) tournament = get_object_or_404(Tournament, pk=tournament_id)
registered_user = None registered_user = None
team_registration = None team_registration = None
is_captain = False
if request.user.is_authenticated: if request.user.is_authenticated:
# Assuming user's licence_id is stored in the user profile (e.g., request.user.licence_id) # 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 the user is registered, retrieve their team registration
if registered_user: if registered_user:
is_captain = registered_user.captain
team_registration = registered_user.team_registration team_registration = registered_user.team_registration
return render(request, 'tournaments/tournament_info.html', { return render(request, 'tournaments/tournament_info.html', {
'tournament': tournament, 'tournament': tournament,
'team': team_registration, 'team': team_registration,
'is_captain': is_captain
}) })
@ -574,8 +578,19 @@ def profile(request):
teamregistration__playerregistration__licence_id__startswith=stripped_license teamregistration__playerregistration__licence_id__startswith=stripped_license
).distinct().order_by('-start_date') ).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', { return render(request, 'registration/profile.html', {
'tournaments': tournaments, 'tournaments': tournaments,
'upcoming_tournaments': upcoming_tournaments,
'running_tournaments': running_tournaments,
'ended_tournaments': ended_tournaments,
'user_name': user.username 'user_name': user.username
}) })
@ -638,10 +653,11 @@ def register_tournament(request, tournament_id):
else: else:
if add_player_form.first_tournament is False: if add_player_form.first_tournament is False:
# Retrieve player names from the CSV file # Retrieve player names from the CSV file
first_name, last_name = get_player_name_from_csv(licence_id) first_name, last_name, rank = get_player_name_from_csv(licence_id)
if first_name and last_name: if first_name and last_name and rank:
player_data['first_name'] = first_name player_data['first_name'] = first_name
player_data['last_name'] = last_name player_data['last_name'] = last_name
player_data['rank'] = rank
# If validation passes, add the player to the session without clearing previous ones # If validation passes, add the player to the session without clearing previous ones
request.session['team_registration'].append(player_data) request.session['team_registration'].append(player_data)
request.session.modified = True # Ensure session is updated request.session.modified = True # Ensure session is updated
@ -656,17 +672,33 @@ def register_tournament(request, tournament_id):
tournament=tournament, tournament=tournament,
registration_date=timezone.now() 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 # Create PlayerRegistration objects for each player in the session
for player_data in request.session['team_registration']: 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( player_registration = PlayerRegistration.objects.create(
team_registration=team_registration, team_registration=team_registration,
captain=is_captain,
source=PlayerDataSource.ONLINE_REGISTRATION,
first_name=player_data['first_name'], first_name=player_data['first_name'],
last_name=player_data['last_name'], last_name=player_data['last_name'],
rank = player_data.get('rank', 70000),
licence_id=player_data['licence_id'], licence_id=player_data['licence_id'],
email = player_data.get('email', None), email = player_data.get('email', None),
phone_number = player_data.get('phone_number', None) phone_number = player_data.get('phone_number', None)
) )
team_registration.set_weight()
request.session['team_registration'] = [] request.session['team_registration'] = []
registration_successful = True registration_successful = True
else: else:
@ -688,6 +720,13 @@ def register_tournament(request, tournament_id):
'phone': request.user.phone, 'phone': request.user.phone,
'licence_id': request.user.licence_id, '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['team_registration'].insert(0, player_data) # Add them as the first player
request.session.modified = True # Ensure session is updated request.session.modified = True # Ensure session is updated

Loading…
Cancel
Save