fix some local date stuff and improve list of tournament in my tourneys view

online_registration
Raz 10 months ago
parent dd6f176fea
commit 61129b318a
  1. 6
      tournaments/models/tournament.py
  2. 36
      tournaments/views.py

@ -807,9 +807,9 @@ class Tournament(models.Model):
if self.end_date is not None: if self.end_date is not None:
return is_build_and_not_empty return is_build_and_not_empty
if datetime.now().date() >= self.start_date.date(): if timezone.now().date() >= timezone.localtime(self.start_date):
return is_build_and_not_empty return is_build_and_not_empty
minimum_publish_date = self.creation_date.replace(hour=9, minute=0) + timedelta(days=1) minimum_publish_date = timezone.localtime(self.creation_date).replace(hour=9, minute=0) + timedelta(days=1)
return timezone.now() >= minimum_publish_date return timezone.now() >= minimum_publish_date
def display_teams(self): def display_teams(self):
@ -1017,7 +1017,7 @@ class Tournament(models.Model):
def get_online_registration_status(self): def get_online_registration_status(self):
if self.supposedly_in_progress(): if self.supposedly_in_progress():
return OnlineRegistrationStatus.IN_PROGRESS return OnlineRegistrationStatus.ENDED
if self.closed_registration_date is not None: if self.closed_registration_date is not None:
return OnlineRegistrationStatus.ENDED return OnlineRegistrationStatus.ENDED
if self.end_date is not None: if self.end_date is not None:

@ -690,32 +690,34 @@ class CustomPasswordResetConfirmView(PasswordResetConfirmView):
@login_required @login_required
def my_tournaments(request): def my_tournaments(request):
user = request.user # Get the currently authenticated user user = request.user
# Assuming the authenticated user has a `licence_id` attribute
user_licence_id = request.user.licence_id user_licence_id = request.user.licence_id
# Check if licence_id is None # If no licence_id, return empty lists
if user_licence_id is None: if user_licence_id is None:
tournaments = Tournament.objects.none() # Return an empty queryset return render(request, 'registration/my_tournaments.html', {
else: 'upcoming_tournaments': [],
'running_tournaments': [],
'ended_tournaments': [],
'user_name': user.username
})
# Get all tournaments for the user based on their licence
validator = LicenseValidator(user_licence_id) validator = LicenseValidator(user_licence_id)
stripped_license = validator.stripped_license stripped_license = validator.stripped_license
# Filter tournaments where the authenticated user's licence_id starts with the given value
tournaments = Tournament.objects.filter(
teamregistration__playerregistration__licence_id__startswith=stripped_license
).distinct().order_by('-start_date')
# Current time def filter_user_tournaments(tournaments):
current_time = timezone.now() return [t for t in tournaments if t.teamregistration_set.filter(
playerregistration__licence_id__startswith=stripped_license,
walk_out=False
).exists()]
# Separate tournaments into categories # Get filtered tournaments using the helper function
upcoming_tournaments = tournaments.filter(start_date__gt=current_time) upcoming_tournaments = filter_user_tournaments(future_tournaments(None))
running_tournaments = tournaments.filter(start_date__lte=current_time, end_date=None) running_tournaments = filter_user_tournaments(live_tournaments(None))
ended_tournaments = tournaments.filter(end_date__isnull=False) ended_tournaments = filter_user_tournaments(finished_tournaments(None))
return render(request, 'registration/my_tournaments.html', { return render(request, 'registration/my_tournaments.html', {
'tournaments': tournaments,
'upcoming_tournaments': upcoming_tournaments, 'upcoming_tournaments': upcoming_tournaments,
'running_tournaments': running_tournaments, 'running_tournaments': running_tournaments,
'ended_tournaments': ended_tournaments, 'ended_tournaments': ended_tournaments,

Loading…
Cancel
Save