diff --git a/padel/settings.py b/padel/settings.py
index 0b7959f..9e0ace7 100644
--- a/padel/settings.py
+++ b/padel/settings.py
@@ -131,6 +131,7 @@ USE_TZ = True
# https://docs.djangoproject.com/en/4.1/howto/static-files/
STATIC_URL = 'static/'
+STATIC_ROOT = 'static/'
# Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
diff --git a/scores/admin.py b/scores/admin.py
index db3ab4e..0640956 100644
--- a/scores/admin.py
+++ b/scores/admin.py
@@ -3,6 +3,8 @@ from django.contrib import admin
# Register your models here.
from .models import Club
from .models import Match
+from .models import Tournament
admin.site.register(Club)
+admin.site.register(Tournament)
admin.site.register(Match)
diff --git a/scores/migrations/0009_remove_match_club_tournament_match_tournament.py b/scores/migrations/0009_remove_match_club_tournament_match_tournament.py
new file mode 100644
index 0000000..e1351db
--- /dev/null
+++ b/scores/migrations/0009_remove_match_club_tournament_match_tournament.py
@@ -0,0 +1,31 @@
+# Generated by Django 4.1.1 on 2023-07-23 12:49
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('scores', '0008_alter_match_enddate'),
+ ]
+
+ operations = [
+ migrations.RemoveField(
+ model_name='match',
+ name='club',
+ ),
+ migrations.CreateModel(
+ name='Tournament',
+ fields=[
+ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('name', models.CharField(max_length=200)),
+ ('club', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='scores.club')),
+ ],
+ ),
+ migrations.AddField(
+ model_name='match',
+ name='tournament',
+ field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, to='scores.tournament'),
+ ),
+ ]
diff --git a/scores/migrations/0010_alter_tournament_club.py b/scores/migrations/0010_alter_tournament_club.py
new file mode 100644
index 0000000..6dd58e2
--- /dev/null
+++ b/scores/migrations/0010_alter_tournament_club.py
@@ -0,0 +1,19 @@
+# Generated by Django 4.1.1 on 2023-07-23 12:50
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('scores', '0009_remove_match_club_tournament_match_tournament'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='tournament',
+ name='club',
+ field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, to='scores.club'),
+ ),
+ ]
diff --git a/scores/models.py b/scores/models.py
index a49c29b..2093db2 100644
--- a/scores/models.py
+++ b/scores/models.py
@@ -9,8 +9,21 @@ class Club(models.Model):
def __str__(self):
return self.name
+class Tournament(models.Model):
+ club = models.ForeignKey(Club, on_delete=models.CASCADE, default=None)
+ name = models.CharField(max_length=200)
+
+ def __str__(self):
+ return self.name
+
+ def live_matches(self):
+ return self.matches.filter(enddate__isnull=True).order_by('court')
+
+ def ended_matches(self):
+ return self.matches.filter(enddate__isnull=False).order_by('court')
+
class Match(models.Model):
- club = models.ForeignKey(Club, on_delete=models.CASCADE)
+ tournament = models.ForeignKey(Tournament, on_delete=models.CASCADE, default=None)
date = models.DateTimeField('start date')
enddate = models.DateTimeField('end date', null=True, blank=True)
court = models.IntegerField(default=0)
@@ -34,7 +47,7 @@ class Match(models.Model):
team2scorecolumn5 = models.CharField(max_length=200, blank=True)
def durationPrefix(self):
-
+
_seconds = 0
if self.enddate:
_seconds = (self.enddate - self.date).total_seconds()
@@ -45,7 +58,7 @@ class Match(models.Model):
return "Temps de jeu"
else :
return "Démarrage prévu dans"
-
+
def duration(self):
_seconds = 0
diff --git a/scores/serializers.py b/scores/serializers.py
index a55865f..193bf62 100644
--- a/scores/serializers.py
+++ b/scores/serializers.py
@@ -1,6 +1,6 @@
from django.contrib.auth.models import User
from rest_framework import serializers
-from .models import Match, Club
+from .models import Match, Club, Tournament
class UserSerializer(serializers.HyperlinkedModelSerializer):
@@ -13,6 +13,11 @@ class ClubSerializer(serializers.HyperlinkedModelSerializer):
model = Club
fields = ['id', 'name', 'header', 'footer']
+class TournamentSerializer(serializers.HyperlinkedModelSerializer):
+ class Meta:
+ model = Tournament
+ fields = ['id', 'name']
+
class MatchSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Match
diff --git a/scores/static/scores/style.css b/scores/static/scores/style.css
index ab8aefd..111f1b5 100644
--- a/scores/static/scores/style.css
+++ b/scores/static/scores/style.css
@@ -5,22 +5,26 @@ html, body {
font-family: -apple-system, BlinkMacSystemFont, monospace;
/*font-family: 'SF Mono', SFMono-Regular, ui-monospace, 'DejaVu Sans Mono', Menlo, Consolas, monospace;*/
/*font-family: Helvetica, sans-serif;*/
- background-color: #3878D8;
- color: white;
+ background-color: white;
+ color: black;
-box-sizing: border-box;
-height: 100%;
-padding: 0;
-margin: 0;
+ box-sizing: border-box;
+ height: 100%;
+ padding: 0;
+ margin: 0;
+}
+
+h1 {
+ font-size: 24px;
}
header, footer {
- padding: 15px;
+ padding: 10px;
}
header {
- font-size: 30px;
+ font-size: 20px;
}
.page-body {
@@ -35,30 +39,30 @@ header {
}
a {
- color: white;
+ color: #3878D8;
}
table {
- font-size: 30px;
- font-weight: 600;
+ font-size: 20px;
+ font-weight: 500;
}
table, th, td {
border: 1px solid;
- border-color: white;
+ border-color: #ddd;
border-collapse: collapse;
}
tr {
- height: 80px;
+ height: 60px;
}
td {
- padding: 10px;
+ padding: 0px 10px;
}
.big {
- font-size: 30px;
+ font-size: 20px;
font-weight: 600;
}
@@ -76,12 +80,33 @@ td {
.match {
/* display: inline-block; */
display:inline-block;
- width: 45%;
- padding: 20px;
+ width: 30%;
+ padding: 0px 20px;
+
+}
+.duration {
+ /* display:grid; */
+ /* grid-template-columns: max-content max-content; */
+ width: 100%;
+ background-color: #fcc;
}
+
+.alignleft {
+ float: left;
+}
+.alignright {
+ float: right;
+}
+.clear {
+ clear: both;
+}
+.teamname {
+ width: 100%;
+}
+
.smatch {
- padding-top: 50px;
+ padding-top: 20px;
width: 800px;
margin: 0 auto;
diff --git a/scores/templates/scores/club.html b/scores/templates/scores/club.html
new file mode 100644
index 0000000..e902bba
--- /dev/null
+++ b/scores/templates/scores/club.html
@@ -0,0 +1,36 @@
+
+
+{% load static %}
+
+
+
+ Padel - {{ club.name }}
+
+
+
+
+
+
+
+ {% if club.header %}
+
+ {% endif %}
+
+
+
+ {% for tournament in tournaments %}
+
+
+
+ {% endfor %}
+
+
+
+ {% if club.footer %}
+
+ {% endif %}
+
+
+
diff --git a/scores/templates/scores/index.html b/scores/templates/scores/index.html
index a8ba009..254220f 100644
--- a/scores/templates/scores/index.html
+++ b/scores/templates/scores/index.html
@@ -1,37 +1,6 @@
{% load static %}
-
@@ -57,29 +26,34 @@ document.getElementById("demo").innerHTML = "Démarrage en cours...";
{{ match.title }}
+
+
{% if match.team3 %}
- | {{ match.team1|linebreaksbr }} |
+
| {{ match.team1|linebreaksbr }} |
{% if match.team1scorecolumn1 %}{{ match.team1scorecolumn1 }} | {% endif %}
{% if match.team2scorecolumn1 %}{{ match.team2scorecolumn1 }} | {% endif %}
- | {{ match.team2|linebreaksbr }} |
+
| {{ match.team2|linebreaksbr }} |
{% if match.team1scorecolumn2 %}{{ match.team1scorecolumn2 }} | {% endif %}
{% if match.team2scorecolumn2 %}{{ match.team2scorecolumn2 }} | {% endif %}
- | {{ match.team3|linebreaksbr }} |
+
| {{ match.team3|linebreaksbr }} |
{% if match.team1scorecolumn3 %}{{ match.team1scorecolumn3 }} | {% endif %}
{% if match.team2scorecolumn3 %}{{ match.team2scorecolumn3 }} | {% endif %}
- | {{ match.team4|linebreaksbr }} |
+
| {{ match.team4|linebreaksbr }} |
{% if match.team1scorecolumn4 %}{{ match.team1scorecolumn4 }} | {% endif %}
{% if match.team2scorecolumn4 %}{{ match.team2scorecolumn4 }} | {% endif %}
{% if match.team5 %}
- | {{ match.team5|linebreaksbr }} |
+
| {{ match.team5|linebreaksbr }} |
{% if match.team1scorecolumn5 %}{{ match.team1scorecolumn5 }} | {% endif %}
{% if match.team2scorecolumn5 %}{{ match.team2scorecolumn5 }} | {% endif %}
@@ -90,7 +64,7 @@ document.getElementById("demo").innerHTML = "Démarrage en cours...";
- | {{ match.team1|linebreaksbr }} |
+ {{ match.team1|linebreaksbr }} |
{% if match.team1scorecolumn1 %}{{ match.team1scorecolumn1 }} | {% endif %}
{% if match.team1scorecolumn2 %}{{ match.team1scorecolumn2 }} | {% endif %}
{% if match.team1scorecolumn3 %}{{ match.team1scorecolumn3 }} | {% endif %}
@@ -98,7 +72,7 @@ document.getElementById("demo").innerHTML = "Démarrage en cours...";
{% if match.team1scorecolumn5 %}{{ match.team1scorecolumn5 }} | {% endif %}
- | {{ match.team2|linebreaksbr }} |
+ {{ match.team2|linebreaksbr }} |
{% if match.team2scorecolumn1 %}{{ match.team2scorecolumn1 }} | {% endif %}
{% if match.team2scorecolumn2 %}{{ match.team2scorecolumn2 }} | {% endif %}
{% if match.team2scorecolumn3 %}{{ match.team2scorecolumn3 }} | {% endif %}
@@ -110,10 +84,12 @@ document.getElementById("demo").innerHTML = "Démarrage en cours...";
{% endif %}
-
-
{{ match.durationPrefix }}
- {{ match.duration }}
+
+
{{ match.durationPrefix }}
+ {{ match.duration }}
+
+
{% endfor %}
@@ -129,26 +105,26 @@ document.getElementById("demo").innerHTML = "Démarrage en cours...";
{% if match.team3 %}
- | {{ match.team1|linebreaksbr }} |
+
| {{ match.team1|linebreaksbr }} |
{% if match.team1scorecolumn1 %}{{ match.team1scorecolumn1 }} | {% endif %}
{% if match.team2scorecolumn1 %}{{ match.team2scorecolumn1 }} | {% endif %}
- | {{ match.team2|linebreaksbr }} |
+
| {{ match.team2|linebreaksbr }} |
{% if match.team1scorecolumn2 %}{{ match.team1scorecolumn2 }} | {% endif %}
{% if match.team2scorecolumn2 %}{{ match.team2scorecolumn2 }} | {% endif %}
- | {{ match.team3|linebreaksbr }} |
+
| {{ match.team3|linebreaksbr }} |
{% if match.team1scorecolumn3 %}{{ match.team1scorecolumn3 }} | {% endif %}
{% if match.team2scorecolumn3 %}{{ match.team2scorecolumn3 }} | {% endif %}
- | {{ match.team4|linebreaksbr }} |
+
| {{ match.team4|linebreaksbr }} |
{% if match.team1scorecolumn4 %}{{ match.team1scorecolumn4 }} | {% endif %}
{% if match.team2scorecolumn4 %}{{ match.team2scorecolumn4 }} | {% endif %}
{% if match.team5 %}
- | {{ match.team5|linebreaksbr }} |
+
| {{ match.team5|linebreaksbr }} |
{% if match.team1scorecolumn5 %}{{ match.team1scorecolumn5 }} | {% endif %}
{% if match.team2scorecolumn5 %}{{ match.team2scorecolumn5 }} | {% endif %}
@@ -159,7 +135,7 @@ document.getElementById("demo").innerHTML = "Démarrage en cours...";
- | {{ match.team1|linebreaksbr }} |
+ {{ match.team1|linebreaksbr }} |
{% if match.team1scorecolumn1 %}{{ match.team1scorecolumn1 }} | {% endif %}
{% if match.team1scorecolumn2 %}{{ match.team1scorecolumn2 }} | {% endif %}
{% if match.team1scorecolumn3 %}{{ match.team1scorecolumn3 }} | {% endif %}
@@ -167,7 +143,7 @@ document.getElementById("demo").innerHTML = "Démarrage en cours...";
{% if match.team1scorecolumn5 %}{{ match.team1scorecolumn5 }} | {% endif %}
- | {{ match.team2|linebreaksbr }} |
+ {{ match.team2|linebreaksbr }} |
{% if match.team2scorecolumn1 %}{{ match.team2scorecolumn1 }} | {% endif %}
{% if match.team2scorecolumn2 %}{{ match.team2scorecolumn2 }} | {% endif %}
{% if match.team2scorecolumn3 %}{{ match.team2scorecolumn3 }} | {% endif %}
@@ -179,11 +155,12 @@ document.getElementById("demo").innerHTML = "Démarrage en cours...";
{% endif %}
-
-
-
{{ match.durationPrefix }}
- {{ match.duration }}
+
+
{{ match.durationPrefix }}
+ {{ match.duration }}
+
+
{% endfor %}
diff --git a/scores/templates/scores/tournament.html b/scores/templates/scores/tournament.html
new file mode 100644
index 0000000..f8ac10e
--- /dev/null
+++ b/scores/templates/scores/tournament.html
@@ -0,0 +1,166 @@
+
+
+{% load static %}
+
+
+
+ Padel
+
+
+
+
+
+ {% if tournament.club.header %}
+
{{ tournament.club.header }}
+ {% endif %}
+
+
+ {% autoescape off %}
+
+
+
+ {% for match in live_matches %}
+
+
+
TERRAIN #{{ match.court }}
+
+
{{ match.title }}
+
+ {% if match.team3 %}
+
+
+ | {{ match.team1|linebreaksbr }} |
+ {% if match.team1scorecolumn1 %}{{ match.team1scorecolumn1 }} | {% endif %}
+ {% if match.team2scorecolumn1 %}{{ match.team2scorecolumn1 }} | {% endif %}
+
+ | {{ match.team2|linebreaksbr }} |
+ {% if match.team1scorecolumn2 %}{{ match.team1scorecolumn2 }} | {% endif %}
+ {% if match.team2scorecolumn2 %}{{ match.team2scorecolumn2 }} | {% endif %}
+
+ | {{ match.team3|linebreaksbr }} |
+ {% if match.team1scorecolumn3 %}{{ match.team1scorecolumn3 }} | {% endif %}
+ {% if match.team2scorecolumn3 %}{{ match.team2scorecolumn3 }} | {% endif %}
+
+ | {{ match.team4|linebreaksbr }} |
+ {% if match.team1scorecolumn4 %}{{ match.team1scorecolumn4 }} | {% endif %}
+ {% if match.team2scorecolumn4 %}{{ match.team2scorecolumn4 }} | {% endif %}
+
+
+ {% if match.team5 %}
+
+ | {{ match.team5|linebreaksbr }} |
+ {% if match.team1scorecolumn5 %}{{ match.team1scorecolumn5 }} | {% endif %}
+ {% if match.team2scorecolumn5 %}{{ match.team2scorecolumn5 }} | {% endif %}
+
+ {% endif %}
+
+
+ {% else %}
+
+
+
+ | {{ match.team1|linebreaksbr }} |
+ {% if match.team1scorecolumn1 %}{{ match.team1scorecolumn1 }} | {% endif %}
+ {% if match.team1scorecolumn2 %}{{ match.team1scorecolumn2 }} | {% endif %}
+ {% if match.team1scorecolumn3 %}{{ match.team1scorecolumn3 }} | {% endif %}
+ {% if match.team1scorecolumn4 %}{{ match.team1scorecolumn4 }} | {% endif %}
+ {% if match.team1scorecolumn5 %}{{ match.team1scorecolumn5 }} | {% endif %}
+
+
+ | {{ match.team2|linebreaksbr }} |
+ {% if match.team2scorecolumn1 %}{{ match.team2scorecolumn1 }} | {% endif %}
+ {% if match.team2scorecolumn2 %}{{ match.team2scorecolumn2 }} | {% endif %}
+ {% if match.team2scorecolumn3 %}{{ match.team2scorecolumn3 }} | {% endif %}
+ {% if match.team2scorecolumn4 %}{{ match.team2scorecolumn4 }} | {% endif %}
+ {% if match.team2scorecolumn5 %}{{ match.team2scorecolumn5 }} | {% endif %}
+
+
+
+ {% endif %}
+
+
+
+
{{ match.durationPrefix }}
+
{{ match.duration }}
+
+
+
+ {% endfor %}
+
+ {% for match in ended_matches %}
+
+
+
{{ match.title }}
+
+ {% if match.team3 %}
+
+
+ | {{ match.team1|linebreaksbr }} |
+ {% if match.team1scorecolumn1 %}{{ match.team1scorecolumn1 }} | {% endif %}
+ {% if match.team2scorecolumn1 %}{{ match.team2scorecolumn1 }} | {% endif %}
+
+ | {{ match.team2|linebreaksbr }} |
+ {% if match.team1scorecolumn2 %}{{ match.team1scorecolumn2 }} | {% endif %}
+ {% if match.team2scorecolumn2 %}{{ match.team2scorecolumn2 }} | {% endif %}
+
+ | {{ match.team3|linebreaksbr }} |
+ {% if match.team1scorecolumn3 %}{{ match.team1scorecolumn3 }} | {% endif %}
+ {% if match.team2scorecolumn3 %}{{ match.team2scorecolumn3 }} | {% endif %}
+
+ | {{ match.team4|linebreaksbr }} |
+ {% if match.team1scorecolumn4 %}{{ match.team1scorecolumn4 }} | {% endif %}
+ {% if match.team2scorecolumn4 %}{{ match.team2scorecolumn4 }} | {% endif %}
+
+
+ {% if match.team5 %}
+
+ | {{ match.team5|linebreaksbr }} |
+ {% if match.team1scorecolumn5 %}{{ match.team1scorecolumn5 }} | {% endif %}
+ {% if match.team2scorecolumn5 %}{{ match.team2scorecolumn5 }} | {% endif %}
+
+ {% endif %}
+
+
+ {% else %}
+
+
+
+ | {{ match.team1|linebreaksbr }} |
+ {% if match.team1scorecolumn1 %}{{ match.team1scorecolumn1 }} | {% endif %}
+ {% if match.team1scorecolumn2 %}{{ match.team1scorecolumn2 }} | {% endif %}
+ {% if match.team1scorecolumn3 %}{{ match.team1scorecolumn3 }} | {% endif %}
+ {% if match.team1scorecolumn4 %}{{ match.team1scorecolumn4 }} | {% endif %}
+ {% if match.team1scorecolumn5 %}{{ match.team1scorecolumn5 }} | {% endif %}
+
+
+ | {{ match.team2|linebreaksbr }} |
+ {% if match.team2scorecolumn1 %}{{ match.team2scorecolumn1 }} | {% endif %}
+ {% if match.team2scorecolumn2 %}{{ match.team2scorecolumn2 }} | {% endif %}
+ {% if match.team2scorecolumn3 %}{{ match.team2scorecolumn3 }} | {% endif %}
+ {% if match.team2scorecolumn4 %}{{ match.team2scorecolumn4 }} | {% endif %}
+ {% if match.team2scorecolumn5 %}{{ match.team2scorecolumn5 }} | {% endif %}
+
+
+
+ {% endif %}
+
+
+
+
{{ match.durationPrefix }}
+
{{ match.duration }}
+
+
+
+ {% endfor %}
+
+
+ {% endautoescape %}
+
+
+ {% if club.footer %}
+
+ {% endif %}
+
+
+
+
diff --git a/scores/urls.py b/scores/urls.py
index d780f10..37e44a3 100644
--- a/scores/urls.py
+++ b/scores/urls.py
@@ -20,5 +20,9 @@ from . import views
urlpatterns = [
path('', views.index, name='index'),
+ path('club//', views.club, name='club'),
+ path('club//', views.club_name, name='club'),
+ path('tournament//', views.tournament, name='tournament'),
+ path('club///', views.tournament_club, name='tournament'),
path('match//', views.match, name='match'),
]
diff --git a/scores/views.py b/scores/views.py
index 405a8d1..f3641dd 100644
--- a/scores/views.py
+++ b/scores/views.py
@@ -2,8 +2,8 @@ from django.shortcuts import render, get_object_or_404
from django.http import HttpResponse
from django.template import loader
from django.contrib.auth.models import User
-from .models import Match, Club
-from .serializers import UserSerializer, MatchSerializer, ClubSerializer
+from .models import Match, Club, Tournament
+from .serializers import UserSerializer, MatchSerializer, ClubSerializer, TournamentSerializer
from rest_framework import viewsets
from rest_framework import permissions
@@ -19,6 +19,45 @@ def index(request):
}
return HttpResponse(template.render(context, request))
+
+def club(request, club_id):
+
+ club = get_object_or_404(Club, pk=club_id)
+ template = loader.get_template('scores/club.html')
+ context = {
+ 'club': club,
+ }
+ return HttpResponse(template.render(context, request))
+
+
+def club_name(request, club_name):
+
+ club = get_object_or_404(Club, name__iexact=club_name.lower())
+ tournaments = Tournament.objects.filter(club=club.id)
+ template = loader.get_template('scores/club.html')
+ context = {
+ 'club': club,
+ 'tournaments': tournaments,
+ }
+ return HttpResponse(template.render(context, request))
+
+def tournament_club(request, club_name, tournament_id):
+ return tournament(request, tournament_id)
+
+def tournament(request, tournament_id):
+
+ tournament = get_object_or_404(Tournament, pk=tournament_id)
+ live_matches = Match.objects.filter(tournament=tournament.id, enddate__isnull=True).order_by('court')
+ ended_matches = Match.objects.filter(tournament=tournament.id, enddate__isnull=False).order_by('court')
+
+ template = loader.get_template('scores/tournament.html')
+ context = {
+ 'tournament': tournament,
+ 'live_matches': live_matches,
+ 'ended_matches': ended_matches,
+ }
+ return HttpResponse(template.render(context, request))
+
def match(request, match_id):
match = get_object_or_404(Match, pk=match_id)
@@ -39,12 +78,20 @@ class UserViewSet(viewsets.ModelViewSet):
class ClubViewSet(viewsets.ModelViewSet):
"""
- API endpoint that allows matches to be viewed or edited.
+ API endpoint that allows clubs to be viewed or edited.
"""
queryset = Club.objects.all().order_by('id')
serializer_class = ClubSerializer
permission_classes = [permissions.IsAuthenticated]
+class TournamentViewSet(viewsets.ModelViewSet):
+ """
+ API endpoint that allows clubs to be viewed or edited.
+ """
+ queryset = Tournament.objects.all().order_by('id')
+ serializer_class = TournamentSerializer
+ permission_classes = [permissions.IsAuthenticated]
+
class MatchViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows matches to be viewed or edited.