diff --git a/requirements.txt b/requirements.txt index a6a3e65..aa6fcb7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,3 +11,4 @@ pandas==2.2.2 xlrd==2.0.1 openpyxl==3.1.5 django-filter==24.3 +cryptography==41.0.7 diff --git a/tournaments/admin.py b/tournaments/admin.py index e05e93f..87dd2c2 100644 --- a/tournaments/admin.py +++ b/tournaments/admin.py @@ -70,7 +70,7 @@ class RoundAdmin(admin.ModelAdmin): class PlayerRegistrationAdmin(admin.ModelAdmin): list_display = ['first_name', 'last_name', 'licence_id', 'rank'] - search_fields = ('first_name', 'last_name') + search_fields = ('first_name', 'last_name', 'licence_id__icontains') list_filter = ['registered_online', TeamScoreTournamentListFilter] ordering = ['last_name', 'first_name'] @@ -111,6 +111,7 @@ class LogAdmin(admin.ModelAdmin): class DeviceTokenAdmin(admin.ModelAdmin): list_display = ['user', 'value'] + list_filter = ['user'] class DrawLogAdmin(admin.ModelAdmin): list_display = ['tournament', 'draw_date', 'draw_seed', 'draw_match_index', 'draw_team_position'] diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 9d8ba06..10f59f3 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -704,25 +704,24 @@ class Tournament(models.Model): # all started matches have ended, possibly last_finished_match = self.last_finished_match() - - round = last_finished_match.round - if round is None: # when the last finished match is in the group stage - round = self.round_set.filter(parent__isnull=True).order_by('-index').first() - - if round: - # print(f'last_finished_match = {last_finished_match.name}') - round_root_index = round.root_round().index - # print(f'round_index = {round_root_index}') - if round_root_index == 0: - return round - else: - round = self.round_set.filter(parent=None,index=round_root_index-1).first() - if round: + if last_finished_match: + round = last_finished_match.round + if round is None: # when the last finished match is in the group stage + round = self.round_set.filter(parent__isnull=True).order_by('-index').first() + + if round: + # print(f'last_finished_match = {last_finished_match.name}') + round_root_index = round.root_round().index + # print(f'round_index = {round_root_index}') + if round_root_index == 0: return round else: - return None - else: - return None + round = self.round_set.filter(parent=None,index=round_root_index-1).first() + if round: + return round + else: + return None + return None def last_started_match(self): matches = [m for m in self.all_matches(False) if m.start_date] diff --git a/tournaments/signals.py b/tournaments/signals.py index 321fde0..848dbca 100644 --- a/tournaments/signals.py +++ b/tournaments/signals.py @@ -53,11 +53,11 @@ def send_discord_message(webhook_url, content): data = { "content": content } - response = requests.post(webhook_url, json=data) - if response.status_code != 204: - raise ValueError( - f'Error sending message to Discord webhook: {response.status_code}, {response.text}' - ) + requests.post(webhook_url, json=data) + # if response.status_code != 204: + # raise ValueError( + # f'Error sending message to Discord webhook: {response.status_code}, {response.text}' + # ) @receiver(pre_delete, sender=TeamRegistration) def unregister_team(sender, instance, **kwargs): diff --git a/tournaments/views.py b/tournaments/views.py index e37ad77..ae0cbb0 100644 --- a/tournaments/views.py +++ b/tournaments/views.py @@ -499,9 +499,12 @@ def download(request): return render(request, 'tournaments/download.html') def test_apns(request): - token = DeviceToken.objects.first() - asyncio.run(send_push_notification(token.value, 'hello!')) + user = CustomUser.objects.filter(username='laurent').first() + for device_token in user.devicetoken_set.all(): + asyncio.run(send_push_notification(device_token.value, 'LOL?!')) + + # token = DeviceToken.objects.first() return HttpResponse('OK!') @@ -897,8 +900,8 @@ class UserListExportView(LoginRequiredMixin, View): # Write header headers = [ - 'Prenom', 'Nom', 'Club', 'Email', 'Telephone', - 'origine', 'Actif', 'Inscription', 'Tournois' + 'Prenom', 'Nom', 'Club', 'Email', 'Telephone', 'Username', + 'Origine', 'Actif', 'Inscription', 'Tournois' ] response.write('\t'.join(headers) + '\n') @@ -910,6 +913,7 @@ class UserListExportView(LoginRequiredMixin, View): str(user.latest_event_club_name() or ''), str(user.email or ''), str(user.phone or ''), + user.username, str(user.get_origin_display()), 'Oui' if user.is_active else 'Non', user.date_joined.strftime('%Y-%m-%d %H:%M:%S'),