From ec7e9eb7059aed9593926a8fbbe89d2a62ec8289 Mon Sep 17 00:00:00 2001 From: Laurent Date: Thu, 2 Mar 2023 12:05:59 +0100 Subject: [PATCH] merge --- scores/migrations/0007_match_enddate.py | 18 +++++++ scores/models.py | 7 ++- scores/serializers.py | 2 +- scores/templates/scores/index.html | 66 ++++++++++++++++++++++++- scores/views.py | 6 ++- 5 files changed, 93 insertions(+), 6 deletions(-) create mode 100644 scores/migrations/0007_match_enddate.py diff --git a/scores/migrations/0007_match_enddate.py b/scores/migrations/0007_match_enddate.py new file mode 100644 index 0000000..6850b05 --- /dev/null +++ b/scores/migrations/0007_match_enddate.py @@ -0,0 +1,18 @@ +# Generated by Django 4.1.1 on 2023-03-02 10:34 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('scores', '0006_club_footer_club_header'), + ] + + operations = [ + migrations.AddField( + model_name='match', + name='enddate', + field=models.DateTimeField(null=True, verbose_name='end date'), + ), + ] diff --git a/scores/models.py b/scores/models.py index 34f2516..8e7905c 100644 --- a/scores/models.py +++ b/scores/models.py @@ -12,6 +12,7 @@ class Club(models.Model): class Match(models.Model): club = models.ForeignKey(Club, on_delete=models.CASCADE) date = models.DateTimeField('start date') + enddate = models.DateTimeField('end date', null=True) court = models.IntegerField(default=0) title = models.CharField(max_length=200, blank=True) @@ -34,7 +35,11 @@ class Match(models.Model): def duration(self): - _seconds = (timezone.now() - self.date).total_seconds() + _seconds = 0 + if self.enddate: + _seconds = (self.enddate - self.date).total_seconds() + else: + _seconds = (timezone.now() - self.date).total_seconds() if _seconds > 0: _hours = int(_seconds / 3600) diff --git a/scores/serializers.py b/scores/serializers.py index e441197..51453df 100644 --- a/scores/serializers.py +++ b/scores/serializers.py @@ -16,6 +16,6 @@ class ClubSerializer(serializers.HyperlinkedModelSerializer): class MatchSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = Match - fields = ['id', 'club', 'date', 'court', 'title', 'team1', 'team2', 'team3', 'team4', + fields = ['id', 'club', 'date', 'enddate', 'court', 'title', 'team1', 'team2', 'team3', 'team4', 'team1scorecolumn1', 'team1scorecolumn2', 'team1scorecolumn3', 'team1scorecolumn4', 'team1scorecolumn5', 'team2scorecolumn1', 'team2scorecolumn2', 'team2scorecolumn3', 'team2scorecolumn4', 'team2scorecolumn5'] diff --git a/scores/templates/scores/index.html b/scores/templates/scores/index.html index 4114a2b..8239425 100644 --- a/scores/templates/scores/index.html +++ b/scores/templates/scores/index.html @@ -48,8 +48,8 @@ document.getElementById("demo").innerHTML = "Démarrage en cours...";
- {% if matches %} - {% for match in matches %} + {% if live_matches %} + {% for match in live_matches %}

COURS #{{ match.court }}

@@ -109,6 +109,68 @@ document.getElementById("demo").innerHTML = "Démarrage en cours..."; {% else %}

Pas de matchs en cours...

{% endif %} + + {% if ended_matches %} + {% for match in ended_matches %} +
+ +

{{ match.title }}

+ + {% if match.team3 %} + + + + {% if match.team1scorecolumn1 %}{% endif %} + + + {% if match.team1scorecolumn2 %}{% endif %} + + + {% if match.team1scorecolumn3 %}{% endif %} + + + {% if match.team1scorecolumn4 %}{% endif %} + + + + {% if match.team1scorecolumn5 %}{% endif %} + +
{{ match.team1 }}{{ match.team1scorecolumn1 }}
{{ match.team2 }}{{ match.team1scorecolumn2 }}
{{ match.team3 }}{{ match.team1scorecolumn3 }}
{{ match.team4 }}{{ match.team1scorecolumn4 }}
{{ match.team5 }}{{ match.team1scorecolumn5 }}
+ {% else %} + + + + + {% if match.team1scorecolumn1 %}{% endif %} + {% if match.team1scorecolumn2 %}{% endif %} + {% if match.team1scorecolumn3 %}{% endif %} + {% if match.team1scorecolumn4 %}{% endif %} + {% if match.team1scorecolumn5 %}{% endif %} + + + + {% if match.team2scorecolumn1 %}{% endif %} + {% if match.team2scorecolumn2 %}{% endif %} + {% if match.team2scorecolumn3 %}{% endif %} + {% if match.team2scorecolumn4 %}{% endif %} + {% if match.team2scorecolumn5 %}{% endif %} + +
{{ match.team1 }}{{ match.team1scorecolumn1 }}{{ match.team1scorecolumn2 }}{{ match.team1scorecolumn3 }}{{ match.team1scorecolumn4 }}{{ match.team1scorecolumn5 }}
{{ match.team2 }}{{ match.team2scorecolumn1 }}{{ match.team2scorecolumn2 }}{{ match.team2scorecolumn3 }}{{ match.team2scorecolumn4 }}{{ match.team2scorecolumn5 }}
+ + {% endif %} + + + +

{{ match.duration }}

+ +
+ {% endfor %} + + {% else %} +

Pas de matchs en cours...

+ {% endif %} + +
diff --git a/scores/views.py b/scores/views.py index 2f06274..405a8d1 100644 --- a/scores/views.py +++ b/scores/views.py @@ -9,11 +9,13 @@ from rest_framework import permissions def index(request): club = Club.objects.first() - matches = Match.objects.order_by('court') + live_matches = Match.objects.filter(enddate__isnull=True).order_by('court') + ended_matches = Match.objects.filter(enddate__isnull=False).order_by('court') template = loader.get_template('scores/index.html') context = { 'club': club, - 'matches': matches, + 'live_matches': live_matches, + 'ended_matches': ended_matches, } return HttpResponse(template.render(context, request))