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. 10
      tournaments/templates/register_tournament.html
  6. 43
      tournaments/templates/registration/profile.html
  7. 4
      tournaments/templates/tournaments/base.html
  8. 29
      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):
FRENCH_FEDERATION = 0, 'French Federation'
BEACH_PADEL = 1, 'Beach Padel'
ONLINE_REGISTRATION = 2, 'Online Registration'
class PlayerSexType(models.IntegerChoices):
FEMALE = 0, 'Female'

@ -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()

@ -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

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

@ -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 %}
<div class="grid-x">
{% if tournaments %}
<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">
{% for tournament in tournaments %}
{% if upcoming_tournaments %}
{% for tournament in upcoming_tournaments %}
{% include 'tournaments/tournament_row.html' %}
{% endfor %}
{% else %}
Aucun tournoi à venir
{% endif %}
</div>
</div>
<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 %}

@ -49,11 +49,7 @@
class="logo inline"
/>
<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>
{% endif %}
<h1 class="event">{% block second_title %}Page Title{% endblock %}</h1>
</div>
</a>

@ -37,33 +37,50 @@
<div>{{ tournament.event.creator.full_name }}</div>
</p>
{% endif %}
{% if tournament.online_register_is_enabled and team is None %}
<p>
<div class="semibold">
L'inscription en ligne est possible.
</div>
</p>
{% if tournament.online_register_is_enabled %}
<p>
<div>
<a href="{% url 'register_tournament' tournament.id %}?reset=true" class="button">S'inscrire</a>
</div>
</p>
{% endif %}
</div>
{% if tournament.online_register_is_enabled and team %}
<h1 class="club my-block topmargin20">Votre équipe</h1 >
<div class="bubble">
{% if team %}
<p>
<div class="semibold">
{% for name in team.player_names_as_list %}
<div>{{ name }}</div>
{% 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>
<a href="{% url 'register_tournament' tournament.id %}?reset=true" class="button">S'inscrire</a>
<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 %}
{% endif %}
</div>
{% endif %}
</div>
</div>

@ -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

@ -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

@ -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

Loading…
Cancel
Save