|
|
|
|
@ -1,65 +1,73 @@ |
|
|
|
|
from django.shortcuts import render, get_object_or_404 |
|
|
|
|
from django.http import HttpResponse |
|
|
|
|
from django.utils.encoding import force_str |
|
|
|
|
from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode |
|
|
|
|
from django.urls import reverse |
|
|
|
|
|
|
|
|
|
from django.views.decorators.csrf import csrf_exempt |
|
|
|
|
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, PlayerSexType |
|
|
|
|
|
|
|
|
|
from .models import Court, DateInterval, Club, Tournament, CustomUser, Event, Round, GroupStage, Match, TeamScore, TeamRegistration, PlayerRegistration, Purchase, FailedApiCall |
|
|
|
|
from .models import TeamSummon, FederalCategory |
|
|
|
|
from datetime import datetime, timedelta |
|
|
|
|
import time |
|
|
|
|
|
|
|
|
|
from django.template import loader |
|
|
|
|
from datetime import date |
|
|
|
|
from django.http import JsonResponse, HttpResponse |
|
|
|
|
from django.db.models import Q |
|
|
|
|
# Standard library imports |
|
|
|
|
import os |
|
|
|
|
import csv |
|
|
|
|
import json |
|
|
|
|
import time |
|
|
|
|
import asyncio |
|
|
|
|
import csv |
|
|
|
|
|
|
|
|
|
from api.tokens import account_activation_token |
|
|
|
|
from datetime import date, datetime, timedelta |
|
|
|
|
|
|
|
|
|
# Third-party imports |
|
|
|
|
from qr_code.qrcode.utils import QRCodeOptions |
|
|
|
|
from .utils.apns import send_push_notification |
|
|
|
|
import os |
|
|
|
|
|
|
|
|
|
from .forms import SimpleForm |
|
|
|
|
from django.core.mail import EmailMessage |
|
|
|
|
from datetime import timedelta |
|
|
|
|
# Django imports |
|
|
|
|
from django.shortcuts import render, redirect, get_object_or_404 |
|
|
|
|
from django.http import HttpResponse, JsonResponse, Http404 |
|
|
|
|
from django.urls import reverse, reverse_lazy |
|
|
|
|
from django.utils import timezone |
|
|
|
|
from django.shortcuts import render, redirect |
|
|
|
|
from django.contrib.auth.forms import UserCreationForm |
|
|
|
|
from django.contrib.auth import login |
|
|
|
|
|
|
|
|
|
from django.urls import reverse |
|
|
|
|
from django.utils.encoding import force_str, force_bytes |
|
|
|
|
from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode |
|
|
|
|
from django.template import loader |
|
|
|
|
from django.template.loader import render_to_string |
|
|
|
|
from django.contrib import messages |
|
|
|
|
from .forms import TournamentRegistrationForm, AddPlayerForm |
|
|
|
|
|
|
|
|
|
from .utils.licence_validator import LicenseValidator |
|
|
|
|
from .utils.player_search import get_player_name_from_csv |
|
|
|
|
|
|
|
|
|
from django.contrib.auth.decorators import login_required |
|
|
|
|
from .forms import SimpleCustomUserCreationForm |
|
|
|
|
from django.contrib.sites.shortcuts import get_current_site |
|
|
|
|
from django.template.loader import render_to_string |
|
|
|
|
from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode |
|
|
|
|
from django.utils.encoding import force_bytes |
|
|
|
|
|
|
|
|
|
from django.contrib.auth.forms import SetPasswordForm |
|
|
|
|
from django.contrib.auth import login |
|
|
|
|
from django.contrib.auth.decorators import login_required |
|
|
|
|
from django.contrib.auth.forms import ( |
|
|
|
|
UserCreationForm, |
|
|
|
|
SetPasswordForm, |
|
|
|
|
) |
|
|
|
|
from django.contrib.auth.views import PasswordResetConfirmView |
|
|
|
|
from django.urls import reverse_lazy |
|
|
|
|
from django.shortcuts import render |
|
|
|
|
from django.utils.http import urlsafe_base64_decode |
|
|
|
|
from django.contrib.auth.tokens import default_token_generator |
|
|
|
|
from django.contrib.auth.models import User |
|
|
|
|
from django.http import Http404 |
|
|
|
|
from django.contrib.auth.tokens import default_token_generator |
|
|
|
|
from django.db.models import Q |
|
|
|
|
from django.views.decorators.csrf import csrf_exempt |
|
|
|
|
from django.core.files.storage import default_storage |
|
|
|
|
from django.core.files.base import ContentFile |
|
|
|
|
from django.core.mail import EmailMessage |
|
|
|
|
|
|
|
|
|
# Local application imports |
|
|
|
|
from .models import ( |
|
|
|
|
Court, |
|
|
|
|
DateInterval, |
|
|
|
|
Club, |
|
|
|
|
Tournament, |
|
|
|
|
CustomUser, |
|
|
|
|
Event, |
|
|
|
|
Round, |
|
|
|
|
GroupStage, |
|
|
|
|
Match, |
|
|
|
|
TeamScore, |
|
|
|
|
TeamRegistration, |
|
|
|
|
PlayerRegistration, |
|
|
|
|
Purchase, |
|
|
|
|
FailedApiCall, |
|
|
|
|
TeamSummon, |
|
|
|
|
FederalCategory, |
|
|
|
|
) |
|
|
|
|
from .forms import ( |
|
|
|
|
SimpleForm, |
|
|
|
|
SimpleCustomUserCreationForm, |
|
|
|
|
TournamentRegistrationForm, |
|
|
|
|
AddPlayerForm, |
|
|
|
|
ProfileUpdateForm, |
|
|
|
|
) |
|
|
|
|
from .utils.apns import send_push_notification |
|
|
|
|
from .utils.licence_validator import LicenseValidator |
|
|
|
|
from .utils.player_search import get_player_name_from_csv |
|
|
|
|
from api.tokens import account_activation_token |
|
|
|
|
from tournaments.models.device_token import DeviceToken |
|
|
|
|
from tournaments.models.player_enums import PlayerDataSource, PlayerSexType |
|
|
|
|
from django.views.generic.edit import UpdateView |
|
|
|
|
|
|
|
|
|
def index(request): |
|
|
|
|
|
|
|
|
|
@ -582,30 +590,7 @@ def profile(request): |
|
|
|
|
# Assuming the authenticated user has a `licence_id` attribute |
|
|
|
|
user_licence_id = request.user.licence_id |
|
|
|
|
|
|
|
|
|
# Check if licence_id is None |
|
|
|
|
if user_licence_id is None: |
|
|
|
|
tournaments = Tournament.objects.none() # Return an empty queryset |
|
|
|
|
else: |
|
|
|
|
validator = LicenseValidator(user_licence_id) |
|
|
|
|
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 |
|
|
|
|
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 |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
@ -880,3 +865,53 @@ class CustomPasswordResetConfirmView(PasswordResetConfirmView): |
|
|
|
|
return user |
|
|
|
|
except (TypeError, ValueError, User.DoesNotExist): |
|
|
|
|
raise Http404("User not found") |
|
|
|
|
|
|
|
|
|
@login_required |
|
|
|
|
def my_tournaments(request): |
|
|
|
|
user = request.user # Get the currently authenticated user |
|
|
|
|
|
|
|
|
|
# Assuming the authenticated user has a `licence_id` attribute |
|
|
|
|
user_licence_id = request.user.licence_id |
|
|
|
|
|
|
|
|
|
# Check if licence_id is None |
|
|
|
|
if user_licence_id is None: |
|
|
|
|
tournaments = Tournament.objects.none() # Return an empty queryset |
|
|
|
|
else: |
|
|
|
|
validator = LicenseValidator(user_licence_id) |
|
|
|
|
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 |
|
|
|
|
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/my_tournaments.html', { |
|
|
|
|
'tournaments': tournaments, |
|
|
|
|
'upcoming_tournaments': upcoming_tournaments, |
|
|
|
|
'running_tournaments': running_tournaments, |
|
|
|
|
'ended_tournaments': ended_tournaments, |
|
|
|
|
'user_name': user.username |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
from django.contrib.auth.forms import PasswordChangeForm |
|
|
|
|
|
|
|
|
|
class ProfileUpdateView(UpdateView): |
|
|
|
|
model = CustomUser |
|
|
|
|
form_class = ProfileUpdateForm |
|
|
|
|
template_name = 'profile.html' |
|
|
|
|
success_url = reverse_lazy('profile') |
|
|
|
|
|
|
|
|
|
def get_object(self, queryset=None): |
|
|
|
|
return self.request.user |
|
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs): |
|
|
|
|
context = super().get_context_data(**kwargs) |
|
|
|
|
context['password_change_form'] = PasswordChangeForm(user=self.request.user) |
|
|
|
|
return context |
|
|
|
|
|