diff --git a/tournaments/filters.py b/tournaments/filters.py index 1b841e6..5d99d79 100644 --- a/tournaments/filters.py +++ b/tournaments/filters.py @@ -1,10 +1,9 @@ from django.contrib import admin -from .models import Club, TeamScore, Tournament, CustomUser, Event, Round, GroupStage, Match, TeamRegistration, PlayerRegistration, Purchase, Court, DateInterval, FailedApiCall +from .models import Tournament, Match from django.db.models import Q from django.utils.translation import gettext_lazy as _ from django.utils import timezone from datetime import timedelta -import uuid from enum import Enum class SimpleTournamentListFilter(admin.SimpleListFilter): diff --git a/tournaments/forms.py b/tournaments/forms.py index 42963b6..94578d2 100644 --- a/tournaments/forms.py +++ b/tournaments/forms.py @@ -5,10 +5,14 @@ import re # Import the re module for regular expressions from .utils.licence_validator import LicenseValidator from django.core.mail import send_mail from django.template.loader import render_to_string -from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode +from django.utils.http import urlsafe_base64_encode from django.contrib.auth.tokens import default_token_generator from django.contrib.sites.shortcuts import get_current_site from django.utils.encoding import force_bytes +from django.contrib.auth.forms import PasswordChangeForm +from django.contrib.auth.forms import AuthenticationForm +from django.contrib.auth import authenticate # Add this import +import logging class CustomUserCreationForm(UserCreationForm): usable_password = None @@ -318,8 +322,6 @@ class ProfileUpdateForm(forms.ModelForm): }, } -from django.contrib.auth.forms import PasswordChangeForm - class CustomPasswordChangeForm(PasswordChangeForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -327,11 +329,6 @@ class CustomPasswordChangeForm(PasswordChangeForm): for field in self.fields.values(): field.widget.attrs.pop("autofocus", None) -from django.contrib.auth.forms import AuthenticationForm -from django.contrib.auth import authenticate # Add this import -from django import forms -import logging - logger = logging.getLogger(__name__) class EmailOrUsernameAuthenticationForm(AuthenticationForm): diff --git a/tournaments/models/enums.py b/tournaments/models/enums.py index 88f9284..d7c7dc2 100644 --- a/tournaments/models/enums.py +++ b/tournaments/models/enums.py @@ -1,5 +1,4 @@ from django.db import models -import uuid class TournamentPayment(models.IntegerChoices): FREE = 0, 'Gratuit' diff --git a/tournaments/models/failed_api_call.py b/tournaments/models/failed_api_call.py index 34e174e..0821a3d 100644 --- a/tournaments/models/failed_api_call.py +++ b/tournaments/models/failed_api_call.py @@ -1,5 +1,5 @@ from django.db import models -from . import BaseModel, CustomUser +from . import CustomUser import uuid class FailedApiCall(models.Model): diff --git a/tournaments/models/log.py b/tournaments/models/log.py index fe36ce6..2be0fea 100644 --- a/tournaments/models/log.py +++ b/tournaments/models/log.py @@ -1,5 +1,5 @@ from django.db import models -from . import BaseModel, CustomUser +from . import CustomUser import uuid class Log(models.Model): diff --git a/tournaments/models/player_enums.py b/tournaments/models/player_enums.py index 59c46a7..1df96b1 100644 --- a/tournaments/models/player_enums.py +++ b/tournaments/models/player_enums.py @@ -1,5 +1,4 @@ from django.db import models -import uuid class PlayerPaymentType(models.IntegerChoices): CASH = 0, 'Cash' diff --git a/tournaments/models/purchase.py b/tournaments/models/purchase.py index 213e30c..29cba73 100644 --- a/tournaments/models/purchase.py +++ b/tournaments/models/purchase.py @@ -1,5 +1,4 @@ from django.db import models -import uuid from . import BaseModel, CustomUser diff --git a/tournaments/models/team_registration.py b/tournaments/models/team_registration.py index ebb2e08..d2360fe 100644 --- a/tournaments/models/team_registration.py +++ b/tournaments/models/team_registration.py @@ -1,9 +1,7 @@ from django.db import models -from django.db.models.sql.query import Q from . import SideStoreModel, Tournament, GroupStage, Match import uuid from django.utils import timezone -from django.db.models import Count class TeamRegistration(SideStoreModel): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True) diff --git a/tournaments/models/team_score.py b/tournaments/models/team_score.py index d30a990..cbf9eee 100644 --- a/tournaments/models/team_score.py +++ b/tournaments/models/team_score.py @@ -1,6 +1,7 @@ from django.db import models -from . import SideStoreModel, Match, TeamRegistration, PlayerRegistration, FederalMatchCategory +from . import SideStoreModel, Match, TeamRegistration, FederalMatchCategory import uuid +from .match import Team # Import Team only when needed class TeamScore(SideStoreModel): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True) @@ -125,7 +126,6 @@ class TeamScore(SideStoreModel): names = self.shortened_team_names() scores = self.parsed_scores() walk_out = self.walk_out - from .match import Team # Import Team only when needed is_lucky_loser = self.lucky_loser is not None team = Team(id, image, names, scores, weight, is_winner, walk_out, is_lucky_loser) return team diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 3f6d2cb..e68c5eb 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -1,19 +1,15 @@ from zoneinfo import ZoneInfo from django.db import models -from typing import TYPE_CHECKING -if TYPE_CHECKING: - from tournaments.models import group_stage - from . import BaseModel, Event, TournamentPayment, FederalMatchCategory, FederalCategory, FederalLevelCategory, FederalAgeCategory, OnlineRegistrationStatus import uuid from django.utils import timezone, formats from datetime import datetime, timedelta, time - from tournaments.utils.player_search import get_player_name_from_csv from shared.cryptography import encryption_util from ..utils.extensions import plural_format from django.utils.formats import date_format from ..utils.licence_validator import LicenseValidator +from django.apps import apps class TeamSortingType(models.IntegerChoices): RANK = 1, 'Rank' @@ -1512,7 +1508,6 @@ class Tournament(BaseModel): return "journée" def get_player_registration_status_by_licence(self, user): - from . import PlayerRegistration licence_id = user.licence_id if not licence_id: return None @@ -1521,6 +1516,7 @@ class Tournament(BaseModel): if validator.validate_license(): stripped_license = validator.stripped_license # Check if there is a PlayerRegistration for this user in this tournament + PlayerRegistration = apps.get_model('tournaments', 'PlayerRegistration') user_player = PlayerRegistration.objects.filter( licence_id__icontains=stripped_license, team_registration__tournament=self, diff --git a/tournaments/models/unregistered_team.py b/tournaments/models/unregistered_team.py index ce0a6a0..a5b91e7 100644 --- a/tournaments/models/unregistered_team.py +++ b/tournaments/models/unregistered_team.py @@ -1,8 +1,6 @@ from django.db import models -from django.db.models.sql.query import Q from . import Tournament import uuid -from django.utils import timezone class UnregisteredTeam(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True) diff --git a/tournaments/services/email_service.py b/tournaments/services/email_service.py index f8f904c..b297224 100644 --- a/tournaments/services/email_service.py +++ b/tournaments/services/email_service.py @@ -1,6 +1,4 @@ from django.core.mail import EmailMessage -from django.utils import timezone -from django.urls import reverse from enum import Enum from ..models.tournament import TeamSortingType diff --git a/tournaments/services/tournament_registration.py b/tournaments/services/tournament_registration.py index 09b8403..258b69f 100644 --- a/tournaments/services/tournament_registration.py +++ b/tournaments/services/tournament_registration.py @@ -52,7 +52,6 @@ class TournamentRegistrationService: return # Clear existing messages if the form is valid - from django.contrib.messages import get_messages storage = get_messages(self.request) # Iterate through the storage to clear it for _ in storage: diff --git a/tournaments/signals.py b/tournaments/signals.py index d51286c..b24ef6a 100644 --- a/tournaments/signals.py +++ b/tournaments/signals.py @@ -1,20 +1,12 @@ import random import string - -from django.db.models.signals import pre_save, post_save, pre_delete, post_delete +from django.db.models.signals import pre_save, post_save, pre_delete from django.dispatch import receiver from django.conf import settings -from django.utils import timezone - -from .models import Club, Tournament, FailedApiCall, CustomUser, Log, TeamRegistration, PlayerRegistration, UnregisteredTeam, UnregisteredPlayer, TeamSortingType, PlayerDataSource +from .models import Club, Tournament, FailedApiCall, Log, TeamRegistration from tournaments.services.email_service import TournamentEmailService - -from tournaments.services.email_service import TournamentEmailService, TeamEmailType -from tournaments.models import PlayerDataSource - +from tournaments.services.email_service import TeamEmailType from shared.discord import send_discord_log_message, send_discord_failed_calls_message -from datetime import datetime - from .utils.extensions import is_not_sqlite_backend def generate_unique_code(): diff --git a/tournaments/urls.py b/tournaments/urls.py index 8019c74..ed91014 100644 --- a/tournaments/urls.py +++ b/tournaments/urls.py @@ -1,12 +1,6 @@ from django.contrib.auth import views as auth_views from django.urls import include, path -from django.contrib import admin -from django.conf import settings -from django.conf.urls.static import static - -from .forms import EmailOrUsernameAuthenticationForm, CustomPasswordChangeForm from .custom_views import CustomLoginView - from . import views urlpatterns = [ diff --git a/tournaments/views.py b/tournaments/views.py index 3d7f52e..1276e17 100644 --- a/tournaments/views.py +++ b/tournaments/views.py @@ -1,6 +1,11 @@ # Standard library imports import os import csv +import pandas as pd +from .utils.extensions import create_random_filename +from api.serializers import GroupStageSerializer, MatchSerializer, PlayerRegistrationSerializer, TeamRegistrationSerializer, TeamScoreSerializer +from django.contrib.auth.mixins import LoginRequiredMixin +from django.contrib.auth import logout from django.contrib.auth import update_session_auth_hash from django.contrib.auth.views import PasswordResetCompleteView @@ -13,29 +18,17 @@ from django.utils.encoding import force_str from django.utils.http import urlsafe_base64_decode from django.urls import reverse from django.conf import settings -from django.db import transaction - from django.views.decorators.csrf import csrf_exempt from django.contrib.admin.views.decorators import staff_member_required from django.core.files.storage import default_storage from django.core.files.base import ContentFile from django.views.generic import View from django.db.models import Q -from django.template import loader - -from tournaments.models.device_token import DeviceToken - -from .models import Court, DateInterval, Club, Tournament, CustomUser, Event, Round, GroupStage, Match, TeamScore, TeamRegistration, PlayerRegistration, Purchase, FailedApiCall, UserOrigin -from .models import TeamSummon +from .models import Club, Tournament, CustomUser, Event, Round, Match, TeamScore, TeamRegistration, PlayerRegistration, UserOrigin from datetime import datetime, timedelta import time - -from datetime import date import json -import time import asyncio -from datetime import date, datetime, timedelta -import csv import zipfile from api.tokens import account_activation_token @@ -44,70 +37,26 @@ from api.tokens import account_activation_token from qr_code.qrcode.utils import QRCodeOptions # 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.http import Http404 +from django.urls import reverse_lazy from django.utils import timezone -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.utils.encoding import force_bytes +from django.utils.http import urlsafe_base64_encode from django.template.loader import render_to_string from django.contrib import messages from django.contrib.sites.shortcuts import get_current_site -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.contrib.auth import get_user_model -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 from django.views.decorators.csrf import csrf_protect from .services.tournament_registration import TournamentRegistrationService from .services.tournament_unregistration import TournamentUnregistrationService from django.core.exceptions import ValidationError - - -# Local application imports -from .models import ( - Court, - DateInterval, - Club, - Tournament, - CustomUser, - Event, - Round, - GroupStage, - Match, - TeamScore, - TeamRegistration, - PlayerRegistration, - Purchase, - FailedApiCall, - TeamSummon, - FederalCategory, - UnregisteredTeam, - UnregisteredPlayer -) 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 from .forms import CustomPasswordChangeForm @@ -531,7 +480,6 @@ def activate(request, uidb64, token): user.save() # Specify the authentication backend when logging in - from django.contrib.auth import login login(request, user, backend='django.contrib.auth.backends.ModelBackend') return redirect('activation_success') @@ -603,9 +551,6 @@ def test_websocket(request): def terms_of_use(request): return render(request, 'terms_of_use.html') -import pandas as pd -from .utils.extensions import create_random_filename - @csrf_exempt def xls_to_csv(request): if request.method == 'POST': @@ -937,8 +882,6 @@ def all_my_ended_tournaments(request): 'title': "Palmarès", }) -from django.contrib.auth.mixins import LoginRequiredMixin - class ProfileUpdateView(LoginRequiredMixin, UpdateView): model = CustomUser form_class = ProfileUpdateForm @@ -954,9 +897,6 @@ class ProfileUpdateView(LoginRequiredMixin, UpdateView): context['password_change_form'] = CustomPasswordChangeForm(user=self.request.user) return context - -from api.serializers import GroupStageSerializer, MatchSerializer, PlayerRegistrationSerializer, TeamRegistrationSerializer, TeamScoreSerializer - @staff_member_required def tournament_import_view(request): if request.method == 'POST': @@ -1169,7 +1109,6 @@ def tournament_prog(request, tournament_id): return render(request, 'tournaments/prog.html', context) def custom_logout(request): - from django.contrib.auth import logout logout(request) return redirect('index') # or whatever URL you want to redirect to