diff --git a/padelclub_backend/settings.py b/padelclub_backend/settings.py index 2dc87a2..3fa806a 100644 --- a/padelclub_backend/settings.py +++ b/padelclub_backend/settings.py @@ -42,6 +42,7 @@ INSTALLED_APPS = [ 'rest_framework', 'rest_framework.authtoken', 'dj_rest_auth', + 'qr_code', ] AUTH_USER_MODEL = "tournaments.CustomUser" diff --git a/padelclub_backend/settings_app.py b/padelclub_backend/settings_app.py index e1f82c8..666ee33 100644 --- a/padelclub_backend/settings_app.py +++ b/padelclub_backend/settings_app.py @@ -28,3 +28,16 @@ EMAIL_HOST_USER = 'xlr@alwaysdata.net' EMAIL_HOST_PASSWORD = 'XLRSport$2024' EMAIL_USE_TLS = True DEFAULT_FROM_EMAIL = 'Padel Club ' + +CACHES = { + 'default': { + 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', + }, + 'qr-code': { + 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', + 'LOCATION': 'qr-code-cache', + 'TIMEOUT': 3600 + } +} + +QR_CODE_CACHE_ALIAS = 'qr-code' diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 5c5e4f4..393a3c6 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -143,7 +143,8 @@ class Tournament(models.Model): now = timezone.now() - today_matches = [match for match in self.all_matches() if match.start_date.date() == now] + today_matches = [match for match in self.all_matches() if match.start_date] + today_matches = [match for match in today_matches if match.start_date.date() == now] today_matches.sort(key=lambda m: m.start_date) matches, group_stages = self.broadcasted_matches_and_group_stages() diff --git a/tournaments/static/tournaments/css/style.css b/tournaments/static/tournaments/css/style.css index 2b84c80..85adb50 100644 --- a/tournaments/static/tournaments/css/style.css +++ b/tournaments/static/tournaments/css/style.css @@ -268,6 +268,10 @@ tr { background-color: red; } +svg { + border-radius: 16px; +} + .bubble { padding: 20px; background-color: white; @@ -514,7 +518,7 @@ tr { .table-row-4-colums { display: grid; - grid-template-columns: 1px auto 50px 70px 150px; /* first column is a hack */ + grid-template-columns: 1px auto 50px 70px 180px; /* first column is a hack */ align-items: center; /* Vertically center the content within each column */ padding: 5px 0px; } diff --git a/tournaments/templates/tournaments/broadcast_base.html b/tournaments/templates/tournaments/broadcast_base.html index 35144a2..6973ccd 100644 --- a/tournaments/templates/tournaments/broadcast_base.html +++ b/tournaments/templates/tournaments/broadcast_base.html @@ -1,6 +1,7 @@ {% load static %} + {% load qr_code %} {% include 'tournaments/base_head.html' %} @@ -28,6 +29,11 @@ +
+
+ {% qr_from_text qr_code_url options=qr_code_options %} +
+
diff --git a/tournaments/templates/tournaments/broadcasted_auto.html b/tournaments/templates/tournaments/broadcasted_auto.html index 3c0a16b..0fd2641 100644 --- a/tournaments/templates/tournaments/broadcasted_auto.html +++ b/tournaments/templates/tournaments/broadcasted_auto.html @@ -1,6 +1,7 @@ {% load static %} + {% load qr_code %} {% include 'tournaments/base_head.html' %} @@ -91,6 +92,11 @@ +
+
+ {% qr_from_text qr_code_url options=qr_code_options %} +
+
diff --git a/tournaments/templates/tournaments/broadcasted_group_stages.html b/tournaments/templates/tournaments/broadcasted_group_stages.html index 3ccfc8d..01d80c6 100644 --- a/tournaments/templates/tournaments/broadcasted_group_stages.html +++ b/tournaments/templates/tournaments/broadcasted_group_stages.html @@ -1,5 +1,7 @@ {% load static %} +{% load qr_code %} + @@ -60,6 +62,11 @@ +
+
+ {% qr_from_text qr_code_url options=qr_code_options %} +
+
diff --git a/tournaments/templates/tournaments/broadcasted_matches.html b/tournaments/templates/tournaments/broadcasted_matches.html index 2959a97..55628af 100644 --- a/tournaments/templates/tournaments/broadcasted_matches.html +++ b/tournaments/templates/tournaments/broadcasted_matches.html @@ -1,5 +1,6 @@ {% load static %} +{% load qr_code %} @@ -58,6 +59,11 @@
+
+
+ {% qr_from_text qr_code_url options=qr_code_options %} +
+
diff --git a/tournaments/views.py b/tournaments/views.py index 552accc..4e6b368 100644 --- a/tournaments/views.py +++ b/tournaments/views.py @@ -2,6 +2,8 @@ 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 .tokens import account_activation_token from tournaments.models import group_stage @@ -24,6 +26,8 @@ from django.http import JsonResponse from django.db.models import Q import json +from qr_code.qrcode.utils import QRCodeOptions + def index(request): today = date.today() @@ -103,6 +107,8 @@ def tournament_broadcasted_summons(request, tournament_id): tournament = get_object_or_404(Tournament, pk=tournament_id) return render(request, 'tournaments/broadcasted_summons.html', { 'tournament': tournament, + 'qr_code_url': qr_code_url(request, tournament_id), + 'qr_code_options': qr_code_options(), }) def tournament_summons_json(request, tournament_id): @@ -115,18 +121,31 @@ def tournament_broadcast_home(request, tournament_id): tournament = get_object_or_404(Tournament, pk=tournament_id) return render(request, 'tournaments/broadcast.html', { 'tournament': tournament, + 'qr_code_url': qr_code_url(request, tournament_id), + 'qr_code_options': qr_code_options(), }) def automatic_broadcast(request, tournament_id): tournament = get_object_or_404(Tournament, pk=tournament_id) return render(request, 'tournaments/broadcasted_auto.html', { 'tournament': tournament, + 'qr_code_url': qr_code_url(request, tournament_id), + 'qr_code_options': qr_code_options(), }) +def qr_code_url(request, tournament_id): + qr_code_url = reverse('tournament', args=[tournament_id]) + return request.build_absolute_uri(qr_code_url) + +def qr_code_options(): + return QRCodeOptions(size=10, border=4, error_correction='L') + def tournament_matches(request, tournament_id): tournament = get_object_or_404(Tournament, pk=tournament_id) return render(request, 'tournaments/broadcasted_matches.html', { 'tournament': tournament, + 'qr_code_url': qr_code_url(request, tournament_id), + 'qr_code_options': qr_code_options(), }) def broadcast_json(request, tournament_id): @@ -155,6 +174,8 @@ def tournament_broadcasted_group_stages(request, tournament_id): tournament = get_object_or_404(Tournament, pk=tournament_id) return render(request, 'tournaments/broadcasted_group_stages.html', { 'tournament': tournament, + 'qr_code_url': qr_code_url(request, tournament_id), + 'qr_code_options': qr_code_options(), }) def tournament_live_group_stage_json(request, tournament_id):