Adds tournaments to club

v2
Laurent 2 years ago
parent f130e9a71e
commit 6da2352ad6
  1. 1
      padel/settings.py
  2. 2
      scores/admin.py
  3. 31
      scores/migrations/0009_remove_match_club_tournament_match_tournament.py
  4. 19
      scores/migrations/0010_alter_tournament_club.py
  5. 19
      scores/models.py
  6. 7
      scores/serializers.py
  7. 61
      scores/static/scores/style.css
  8. 36
      scores/templates/scores/club.html
  9. 81
      scores/templates/scores/index.html
  10. 166
      scores/templates/scores/tournament.html
  11. 4
      scores/urls.py
  12. 53
      scores/views.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

@ -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)

@ -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'),
),
]

@ -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'),
),
]

@ -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

@ -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

@ -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;

@ -0,0 +1,36 @@
<html>
{% load static %}
<head>
<link rel="stylesheet" href="{% static 'scores/style.css' %}">
<title>Padel - {{ club.name }}</title>
<meta http-equiv="refresh" content="15"/>
</head>
<!-- <p id="demo"></p> -->
<div class="wrapper">
{% if club.header %}
<header class="center">{{ club.header }}</header>
{% endif %}
<main class="page-body">
{% for tournament in tournaments %}
<ul>
<li><a href="{{ tournament.id }}/">{{ tournament.name }}</a></li>
</ul>
{% endfor %}
</main>
{% if club.footer %}
<footer class="page-footer, center">{{ club.footer }}</footer>
{% endif %}
</html>

@ -1,37 +1,6 @@
<html>
{% load static %}
<!--
<script>
// Set the date we're counting down to
var countDownDate = new Date("Jan 5, 2024 15:37:25").getTime();
// Update the count down every 1 second
var x = setInterval(function() {
// Get today's date and time
var now = new Date().getTime();
// Find the distance between now and the count down date
var distance = {{ match.seconds }} * -1;
// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Display the result in the element with id="demo"
document.getElementById("demo").innerHTML = hours + "h "
+ minutes + "m " + seconds + "s ";
// If the count down is finished, write some text
if (distance < 0) {
clearInterval(x);
document.getElementById("demo").innerHTML = "Démarrage en cours...";
}
}, 1000);
</script> -->
<head>
<link rel="stylesheet" href="{% static 'scores/style.css' %}">
@ -57,29 +26,34 @@ document.getElementById("demo").innerHTML = "Démarrage en cours...";
<h1>{{ match.title }}</h1>
<!-- <p class="duration">
<div class="alignleft"><h1>{{ match.title }}</h1></div>
<div class="big alignright"><a href="/match/{{ match.id }}/">TERRAIN #{{ match.court }}</a></div>
</p> -->
{% if match.team3 %}
<table>
<tr><td>{{ match.team1|linebreaksbr }}</td>
<tr><td class="teamname">{{ match.team1|linebreaksbr }}</td>
{% if match.team1scorecolumn1 %}<td class="score">{{ match.team1scorecolumn1 }}</td>{% endif %}
{% if match.team2scorecolumn1 %}<td class="score">{{ match.team2scorecolumn1 }}</td>{% endif %}
</tr>
<tr><td>{{ match.team2|linebreaksbr }}</td>
<tr><td class="teamname">{{ match.team2|linebreaksbr }}</td>
{% if match.team1scorecolumn2 %}<td class="score">{{ match.team1scorecolumn2 }}</td>{% endif %}
{% if match.team2scorecolumn2 %}<td class="score">{{ match.team2scorecolumn2 }}</td>{% endif %}
</tr>
<tr><td>{{ match.team3|linebreaksbr }}</td>
<tr><td class="teamname">{{ match.team3|linebreaksbr }}</td>
{% if match.team1scorecolumn3 %}<td class="score">{{ match.team1scorecolumn3 }}</td>{% endif %}
{% if match.team2scorecolumn3 %}<td class="score">{{ match.team2scorecolumn3 }}</td>{% endif %}
</tr>
<tr><td>{{ match.team4|linebreaksbr }}</td>
<tr><td class="teamname">{{ match.team4|linebreaksbr }}</td>
{% if match.team1scorecolumn4 %}<td class="score">{{ match.team1scorecolumn4 }}</td>{% endif %}
{% if match.team2scorecolumn4 %}<td class="score">{{ match.team2scorecolumn4 }}</td>{% endif %}
</tr>
{% if match.team5 %}
<tr><td>{{ match.team5|linebreaksbr }}</td>
<tr><td class="teamname">{{ match.team5|linebreaksbr }}</td>
{% if match.team1scorecolumn5 %}<td class="score">{{ match.team1scorecolumn5 }}</td>{% endif %}
{% if match.team2scorecolumn5 %}<td class="score">{{ match.team2scorecolumn5 }}</td>{% endif %}
</tr>
@ -90,7 +64,7 @@ document.getElementById("demo").innerHTML = "Démarrage en cours...";
<table>
<tr>
<td>{{ match.team1|linebreaksbr }}</td>
<td class="teamname">{{ match.team1|linebreaksbr }}</td>
{% if match.team1scorecolumn1 %}<td class="score">{{ match.team1scorecolumn1 }}</td>{% endif %}
{% if match.team1scorecolumn2 %}<td class="score">{{ match.team1scorecolumn2 }}</td>{% endif %}
{% if match.team1scorecolumn3 %}<td class="score">{{ match.team1scorecolumn3 }}</td>{% endif %}
@ -98,7 +72,7 @@ document.getElementById("demo").innerHTML = "Démarrage en cours...";
{% if match.team1scorecolumn5 %}<td class="score">{{ match.team1scorecolumn5 }}</td>{% endif %}
</tr>
<tr>
<td>{{ match.team2|linebreaksbr }}</td>
<td class="teamname">{{ match.team2|linebreaksbr }}</td>
{% if match.team2scorecolumn1 %}<td class="score">{{ match.team2scorecolumn1 }}</td>{% endif %}
{% if match.team2scorecolumn2 %}<td class="score">{{ match.team2scorecolumn2 }}</td>{% endif %}
{% if match.team2scorecolumn3 %}<td class="score">{{ match.team2scorecolumn3 }}</td>{% endif %}
@ -110,10 +84,12 @@ document.getElementById("demo").innerHTML = "Démarrage en cours...";
{% endif %}
<!-- <p id="demo"></p> -->
<p>
<div class="small">{{ match.durationPrefix }}</div>
<div class="big">{{ match.duration }}</div>
<p class="duration">
<div class="alignleft">{{ match.durationPrefix }}</div>
<div class="big alignright">{{ match.duration }}</div>
</p>
<div class="clear" />
</div>
{% endfor %}
@ -129,26 +105,26 @@ document.getElementById("demo").innerHTML = "Démarrage en cours...";
{% if match.team3 %}
<table>
<tr><td>{{ match.team1|linebreaksbr }}</td>
<tr><td class="teamname">{{ match.team1|linebreaksbr }}</td>
{% if match.team1scorecolumn1 %}<td class="score">{{ match.team1scorecolumn1 }}</td>{% endif %}
{% if match.team2scorecolumn1 %}<td class="score">{{ match.team2scorecolumn1 }}</td>{% endif %}
</tr>
<tr><td>{{ match.team2|linebreaksbr }}</td>
<tr><td class="teamname">{{ match.team2|linebreaksbr }}</td>
{% if match.team1scorecolumn2 %}<td class="score">{{ match.team1scorecolumn2 }}</td>{% endif %}
{% if match.team2scorecolumn2 %}<td class="score">{{ match.team2scorecolumn2 }}</td>{% endif %}
</tr>
<tr><td>{{ match.team3|linebreaksbr }}</td>
<tr><td class="teamname">{{ match.team3|linebreaksbr }}</td>
{% if match.team1scorecolumn3 %}<td class="score">{{ match.team1scorecolumn3 }}</td>{% endif %}
{% if match.team2scorecolumn3 %}<td class="score">{{ match.team2scorecolumn3 }}</td>{% endif %}
</tr>
<tr><td>{{ match.team4|linebreaksbr }}</td>
<tr><td class="teamname">{{ match.team4|linebreaksbr }}</td>
{% if match.team1scorecolumn4 %}<td class="score">{{ match.team1scorecolumn4 }}</td>{% endif %}
{% if match.team2scorecolumn4 %}<td class="score">{{ match.team2scorecolumn4 }}</td>{% endif %}
</tr>
{% if match.team5 %}
<tr><td>{{ match.team5|linebreaksbr }}</td>
<tr><td class="teamname">{{ match.team5|linebreaksbr }}</td>
{% if match.team1scorecolumn5 %}<td class="score">{{ match.team1scorecolumn5 }}</td>{% endif %}
{% if match.team2scorecolumn5 %}<td class="score">{{ match.team2scorecolumn5 }}</td>{% endif %}
</tr>
@ -159,7 +135,7 @@ document.getElementById("demo").innerHTML = "Démarrage en cours...";
<table>
<tr>
<td>{{ match.team1|linebreaksbr }}</td>
<td class="teamname">{{ match.team1|linebreaksbr }}</td>
{% if match.team1scorecolumn1 %}<td class="score">{{ match.team1scorecolumn1 }}</td>{% endif %}
{% if match.team1scorecolumn2 %}<td class="score">{{ match.team1scorecolumn2 }}</td>{% endif %}
{% if match.team1scorecolumn3 %}<td class="score">{{ match.team1scorecolumn3 }}</td>{% endif %}
@ -167,7 +143,7 @@ document.getElementById("demo").innerHTML = "Démarrage en cours...";
{% if match.team1scorecolumn5 %}<td class="score">{{ match.team1scorecolumn5 }}</td>{% endif %}
</tr>
<tr>
<td>{{ match.team2|linebreaksbr }}</td>
<td class="teamname">{{ match.team2|linebreaksbr }}</td>
{% if match.team2scorecolumn1 %}<td class="score">{{ match.team2scorecolumn1 }}</td>{% endif %}
{% if match.team2scorecolumn2 %}<td class="score">{{ match.team2scorecolumn2 }}</td>{% endif %}
{% if match.team2scorecolumn3 %}<td class="score">{{ match.team2scorecolumn3 }}</td>{% endif %}
@ -179,11 +155,12 @@ document.getElementById("demo").innerHTML = "Démarrage en cours...";
{% endif %}
<!-- <p id="demo"></p> -->
<p>
<div class="small">{{ match.durationPrefix }}</div>
<div class="big">{{ match.duration }}</div>
<p class="duration">
<div class="alignleft">{{ match.durationPrefix }}</div>
<div class="big alignright">{{ match.duration }}</div>
</p>
<div class="clear" />
</div>
{% endfor %}

@ -0,0 +1,166 @@
<html>
{% load static %}
<head>
<link rel="stylesheet" href="{% static 'scores/style.css' %}">
<title>Padel</title>
<meta http-equiv="refresh" content="15"/>
</head>
<div class="wrapper">
{% if tournament.club.header %}
<header class="center">{{ tournament.club.header }}</header>
{% endif %}
<main class="page-body">
{% autoescape off %}
<div class="container">
{% for match in live_matches %}
<div class="match">
<p><a href="/match/{{ match.id }}/">TERRAIN #{{ match.court }}</a></p>
<h1>{{ match.title }}</h1>
{% if match.team3 %}
<table>
<tr><td>{{ match.team1|linebreaksbr }}</td>
{% if match.team1scorecolumn1 %}<td class="score">{{ match.team1scorecolumn1 }}</td>{% endif %}
{% if match.team2scorecolumn1 %}<td class="score">{{ match.team2scorecolumn1 }}</td>{% endif %}
</tr>
<tr><td>{{ match.team2|linebreaksbr }}</td>
{% if match.team1scorecolumn2 %}<td class="score">{{ match.team1scorecolumn2 }}</td>{% endif %}
{% if match.team2scorecolumn2 %}<td class="score">{{ match.team2scorecolumn2 }}</td>{% endif %}
</tr>
<tr><td>{{ match.team3|linebreaksbr }}</td>
{% if match.team1scorecolumn3 %}<td class="score">{{ match.team1scorecolumn3 }}</td>{% endif %}
{% if match.team2scorecolumn3 %}<td class="score">{{ match.team2scorecolumn3 }}</td>{% endif %}
</tr>
<tr><td>{{ match.team4|linebreaksbr }}</td>
{% if match.team1scorecolumn4 %}<td class="score">{{ match.team1scorecolumn4 }}</td>{% endif %}
{% if match.team2scorecolumn4 %}<td class="score">{{ match.team2scorecolumn4 }}</td>{% endif %}
</tr>
{% if match.team5 %}
<tr><td>{{ match.team5|linebreaksbr }}</td>
{% if match.team1scorecolumn5 %}<td class="score">{{ match.team1scorecolumn5 }}</td>{% endif %}
{% if match.team2scorecolumn5 %}<td class="score">{{ match.team2scorecolumn5 }}</td>{% endif %}
</tr>
{% endif %}
</table>
{% else %}
<table>
<tr>
<td>{{ match.team1|linebreaksbr }}</td>
{% if match.team1scorecolumn1 %}<td class="score">{{ match.team1scorecolumn1 }}</td>{% endif %}
{% if match.team1scorecolumn2 %}<td class="score">{{ match.team1scorecolumn2 }}</td>{% endif %}
{% if match.team1scorecolumn3 %}<td class="score">{{ match.team1scorecolumn3 }}</td>{% endif %}
{% if match.team1scorecolumn4 %}<td class="score">{{ match.team1scorecolumn4 }}</td>{% endif %}
{% if match.team1scorecolumn5 %}<td class="score">{{ match.team1scorecolumn5 }}</td>{% endif %}
</tr>
<tr>
<td>{{ match.team2|linebreaksbr }}</td>
{% if match.team2scorecolumn1 %}<td class="score">{{ match.team2scorecolumn1 }}</td>{% endif %}
{% if match.team2scorecolumn2 %}<td class="score">{{ match.team2scorecolumn2 }}</td>{% endif %}
{% if match.team2scorecolumn3 %}<td class="score">{{ match.team2scorecolumn3 }}</td>{% endif %}
{% if match.team2scorecolumn4 %}<td class="score">{{ match.team2scorecolumn4 }}</td>{% endif %}
{% if match.team2scorecolumn5 %}<td class="score">{{ match.team2scorecolumn5 }}</td>{% endif %}
</tr>
</table>
{% endif %}
<!-- <p id="demo"></p> -->
<p class="duration">
<div class="alignleft">{{ match.durationPrefix }}</div>
<div class="big alignright">{{ match.duration }}</div>
</p>
</div>
{% endfor %}
{% for match in ended_matches %}
<div class="match">
<h1>{{ match.title }}</h1>
{% if match.team3 %}
<table>
<tr><td>{{ match.team1|linebreaksbr }}</td>
{% if match.team1scorecolumn1 %}<td class="score">{{ match.team1scorecolumn1 }}</td>{% endif %}
{% if match.team2scorecolumn1 %}<td class="score">{{ match.team2scorecolumn1 }}</td>{% endif %}
</tr>
<tr><td>{{ match.team2|linebreaksbr }}</td>
{% if match.team1scorecolumn2 %}<td class="score">{{ match.team1scorecolumn2 }}</td>{% endif %}
{% if match.team2scorecolumn2 %}<td class="score">{{ match.team2scorecolumn2 }}</td>{% endif %}
</tr>
<tr><td>{{ match.team3|linebreaksbr }}</td>
{% if match.team1scorecolumn3 %}<td class="score">{{ match.team1scorecolumn3 }}</td>{% endif %}
{% if match.team2scorecolumn3 %}<td class="score">{{ match.team2scorecolumn3 }}</td>{% endif %}
</tr>
<tr><td>{{ match.team4|linebreaksbr }}</td>
{% if match.team1scorecolumn4 %}<td class="score">{{ match.team1scorecolumn4 }}</td>{% endif %}
{% if match.team2scorecolumn4 %}<td class="score">{{ match.team2scorecolumn4 }}</td>{% endif %}
</tr>
{% if match.team5 %}
<tr><td>{{ match.team5|linebreaksbr }}</td>
{% if match.team1scorecolumn5 %}<td class="score">{{ match.team1scorecolumn5 }}</td>{% endif %}
{% if match.team2scorecolumn5 %}<td class="score">{{ match.team2scorecolumn5 }}</td>{% endif %}
</tr>
{% endif %}
</table>
{% else %}
<table>
<tr>
<td>{{ match.team1|linebreaksbr }}</td>
{% if match.team1scorecolumn1 %}<td class="score">{{ match.team1scorecolumn1 }}</td>{% endif %}
{% if match.team1scorecolumn2 %}<td class="score">{{ match.team1scorecolumn2 }}</td>{% endif %}
{% if match.team1scorecolumn3 %}<td class="score">{{ match.team1scorecolumn3 }}</td>{% endif %}
{% if match.team1scorecolumn4 %}<td class="score">{{ match.team1scorecolumn4 }}</td>{% endif %}
{% if match.team1scorecolumn5 %}<td class="score">{{ match.team1scorecolumn5 }}</td>{% endif %}
</tr>
<tr>
<td>{{ match.team2|linebreaksbr }}</td>
{% if match.team2scorecolumn1 %}<td class="score">{{ match.team2scorecolumn1 }}</td>{% endif %}
{% if match.team2scorecolumn2 %}<td class="score">{{ match.team2scorecolumn2 }}</td>{% endif %}
{% if match.team2scorecolumn3 %}<td class="score">{{ match.team2scorecolumn3 }}</td>{% endif %}
{% if match.team2scorecolumn4 %}<td class="score">{{ match.team2scorecolumn4 }}</td>{% endif %}
{% if match.team2scorecolumn5 %}<td class="score">{{ match.team2scorecolumn5 }}</td>{% endif %}
</tr>
</table>
{% endif %}
<!-- <p id="demo"></p> -->
<p class="duration">
<div class="alignleft">{{ match.durationPrefix }}</div>
<div class="big alignright">{{ match.duration }}</div>
</p>
</div>
{% endfor %}
</div>
{% endautoescape %}
</main>
{% if club.footer %}
<footer class="page-footer, center">{{ club.footer }}</footer>
{% endif %}
</div>
</html>

@ -20,5 +20,9 @@ from . import views
urlpatterns = [
path('', views.index, name='index'),
path('club/<int:club_id>/', views.club, name='club'),
path('club/<str:club_name>/', views.club_name, name='club'),
path('tournament/<int:tournament_id>/', views.tournament, name='tournament'),
path('club/<str:club_name>/<int:tournament_id>/', views.tournament_club, name='tournament'),
path('match/<int:match_id>/', views.match, name='match'),
]

@ -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.

Loading…
Cancel
Save