From dec2d98ca1bbfdf3cdc711e6a649ed7b5f8c6ce0 Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 18 Feb 2025 11:11:08 +0100 Subject: [PATCH 01/10] Adds username column --- tournaments/views.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tournaments/views.py b/tournaments/views.py index e37ad77..5f847c5 100644 --- a/tournaments/views.py +++ b/tournaments/views.py @@ -897,8 +897,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 +910,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'), From d587f301043259cfbeb433819cce1aedcb89c5d0 Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 18 Feb 2025 11:25:33 +0100 Subject: [PATCH 02/10] add fields to the PlayerRegistration search --- tournaments/admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tournaments/admin.py b/tournaments/admin.py index e05e93f..e93fdfc 100644 --- a/tournaments/admin.py +++ b/tournaments/admin.py @@ -60,7 +60,7 @@ class TeamRegistrationAdmin(admin.ModelAdmin): class TeamScoreAdmin(admin.ModelAdmin): list_display = ['team_registration', 'score', 'walk_out', 'match'] list_filter = [TeamScoreTournamentListFilter] - search_fields = ['id'] + search_fields = ['id', 'licence_id', 'first_name', 'last_name'] class RoundAdmin(admin.ModelAdmin): list_display = ['tournament', 'name', 'index', 'parent'] From 5dd2ec63eda4a948a96e8059358acbca489002a9 Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 18 Feb 2025 11:32:50 +0100 Subject: [PATCH 03/10] Add contain for licence_id search --- tournaments/admin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tournaments/admin.py b/tournaments/admin.py index e93fdfc..4678f32 100644 --- a/tournaments/admin.py +++ b/tournaments/admin.py @@ -60,7 +60,7 @@ class TeamRegistrationAdmin(admin.ModelAdmin): class TeamScoreAdmin(admin.ModelAdmin): list_display = ['team_registration', 'score', 'walk_out', 'match'] list_filter = [TeamScoreTournamentListFilter] - search_fields = ['id', 'licence_id', 'first_name', 'last_name'] + search_fields = ['id'] class RoundAdmin(admin.ModelAdmin): list_display = ['tournament', 'name', 'index', 'parent'] @@ -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'] From eee120a78976941a1010c435cf8992e13f75b184 Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 18 Feb 2025 12:04:00 +0100 Subject: [PATCH 04/10] test apns --- tournaments/views.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tournaments/views.py b/tournaments/views.py index 5f847c5..c7d69ca 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='razmig').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!') From 88920886b6947c04400a80fba50b61a96f197cf4 Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 18 Feb 2025 12:09:12 +0100 Subject: [PATCH 05/10] test apns 2 --- requirements.txt | 1 + tournaments/views.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) 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/views.py b/tournaments/views.py index c7d69ca..ae0cbb0 100644 --- a/tournaments/views.py +++ b/tournaments/views.py @@ -500,7 +500,7 @@ def download(request): def test_apns(request): - user = CustomUser.objects.filter(username='razmig').first() + user = CustomUser.objects.filter(username='laurent').first() for device_token in user.devicetoken_set.all(): asyncio.run(send_push_notification(device_token.value, 'LOL?!')) From 24b13744a8db6bfb43842ea9cb3e2b0019c640e5 Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 18 Feb 2025 14:40:25 +0100 Subject: [PATCH 06/10] Adds user filter for DeviceToken --- tournaments/admin.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tournaments/admin.py b/tournaments/admin.py index 4678f32..87dd2c2 100644 --- a/tournaments/admin.py +++ b/tournaments/admin.py @@ -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'] From ea1ce89f285c1be29e67f688d688fe295056d54b Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 18 Feb 2025 15:12:49 +0100 Subject: [PATCH 07/10] test for apns --- tournaments/views.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tournaments/views.py b/tournaments/views.py index ae0cbb0..6d40c4e 100644 --- a/tournaments/views.py +++ b/tournaments/views.py @@ -498,15 +498,26 @@ def club_broadcast_auto(request, broadcast_code): def download(request): return render(request, 'tournaments/download.html') +import jwt +import cryptography +import httpx +from django.http import JsonResponse + def test_apns(request): - user = CustomUser.objects.filter(username='laurent').first() - for device_token in user.devicetoken_set.all(): - asyncio.run(send_push_notification(device_token.value, 'LOL?!')) + return JsonResponse({ + "jwt_version": jwt.__version__, + "cryptography_version": cryptography.__version__, + "httpx_version": httpx.__version__ + }) + + # 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() + # # token = DeviceToken.objects.first() - return HttpResponse('OK!') + # return HttpResponse('OK!') def test_websocket(request): return render(request, 'tournaments/test_websocket.html') From ecd33197a217c31995ef42a2786db6984e2d43b5 Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 18 Feb 2025 15:16:48 +0100 Subject: [PATCH 08/10] revert --- tournaments/views.py | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/tournaments/views.py b/tournaments/views.py index 6d40c4e..ae0cbb0 100644 --- a/tournaments/views.py +++ b/tournaments/views.py @@ -498,26 +498,15 @@ def club_broadcast_auto(request, broadcast_code): def download(request): return render(request, 'tournaments/download.html') -import jwt -import cryptography -import httpx -from django.http import JsonResponse - def test_apns(request): - return JsonResponse({ - "jwt_version": jwt.__version__, - "cryptography_version": cryptography.__version__, - "httpx_version": httpx.__version__ - }) - - # user = CustomUser.objects.filter(username='laurent').first() - # for device_token in user.devicetoken_set.all(): - # asyncio.run(send_push_notification(device_token.value, 'LOL?!')) + 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() + # token = DeviceToken.objects.first() - # return HttpResponse('OK!') + return HttpResponse('OK!') def test_websocket(request): return render(request, 'tournaments/test_websocket.html') From 5013342c83c0ecded55fc6f8168a6004618fe7c2 Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 19 Feb 2025 09:35:51 +0100 Subject: [PATCH 09/10] stop sending discord errors --- tournaments/signals.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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): From d0de8bfb9b3a279519667f3c56478af9ab116cdc Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 19 Feb 2025 10:02:34 +0100 Subject: [PATCH 10/10] Fix crash --- tournaments/models/tournament.py | 33 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 17 deletions(-) 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]