parent
fa014aa11d
commit
90c18edf05
@ -0,0 +1,18 @@ |
||||
# Generated by Django 4.1.1 on 2023-02-23 15:38 |
||||
|
||||
from django.db import migrations, models |
||||
|
||||
|
||||
class Migration(migrations.Migration): |
||||
|
||||
dependencies = [ |
||||
('scores', '0004_match_court'), |
||||
] |
||||
|
||||
operations = [ |
||||
migrations.AddField( |
||||
model_name='match', |
||||
name='team5', |
||||
field=models.CharField(blank=True, max_length=200), |
||||
), |
||||
] |
||||
@ -0,0 +1,16 @@ |
||||
from django.contrib.auth.models import User |
||||
from rest_framework import serializers |
||||
from .models import Match |
||||
|
||||
|
||||
class UserSerializer(serializers.HyperlinkedModelSerializer): |
||||
class Meta: |
||||
model = User |
||||
fields = ['url', 'username', 'email'] |
||||
|
||||
class MatchSerializer(serializers.HyperlinkedModelSerializer): |
||||
class Meta: |
||||
model = Match |
||||
fields = ['id', 'date', 'title', 'team1', 'team2', 'team3', 'team4', |
||||
'team1scorecolumn1', 'team1scorecolumn2', 'team1scorecolumn3', 'team1scorecolumn4', 'team1scorecolumn5', |
||||
'team2scorecolumn1', 'team2scorecolumn2', 'team2scorecolumn3', 'team2scorecolumn4', 'team2scorecolumn5'] |
||||
@ -0,0 +1,104 @@ |
||||
<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 = countDownDate - now; |
||||
|
||||
// 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 = "EXPIRED"; |
||||
} |
||||
}, 1000); |
||||
</script> --> |
||||
|
||||
<head> |
||||
<link rel="stylesheet" href="{% static 'scores/style.css' %}"> |
||||
<title>Padel - {{ match.title }} - COURS {{ match.court }}</title> |
||||
<!-- <meta http-equiv="refresh" content="5" > --> |
||||
</head> |
||||
|
||||
<!-- <p id="demo"></p> --> |
||||
|
||||
<div class="scontainer"> |
||||
{% if match %} |
||||
<div class="smatch"> |
||||
|
||||
<p>COURS {{ match.court }}</p> |
||||
|
||||
<h1>{{ match.title }}</h1> |
||||
|
||||
{% if match.team3 %} |
||||
|
||||
<table> |
||||
<tr><td>{{ match.team1 }}</td> |
||||
{% if match.team1scorecolumn1 %}<td class="score">{{ match.team1scorecolumn1 }}</td>{% endif %} |
||||
</tr> |
||||
<tr><td>{{ match.team2 }}</td> |
||||
{% if match.team1scorecolumn2 %}<td class="score">{{ match.team1scorecolumn2 }}</td>{% endif %} |
||||
</tr> |
||||
<tr><td>{{ match.team3 }}</td> |
||||
{% if match.team1scorecolumn3 %}<td class="score">{{ match.team1scorecolumn3 }}</td>{% endif %} |
||||
</tr> |
||||
<tr><td>{{ match.team4 }}</td> |
||||
{% if match.team1scorecolumn4 %}<td class="score">{{ match.team1scorecolumn4 }}</td>{% endif %} |
||||
</tr> |
||||
|
||||
<tr><td>{{ match.team5 }}</td> |
||||
{% if match.team1scorecolumn5 %}<td class="score">{{ match.team1scorecolumn5 }}</td>{% endif %} |
||||
</tr> |
||||
</table> |
||||
{% else %} |
||||
|
||||
<table> |
||||
<tr> |
||||
<td>{{ match.team1 }}</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 }}</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>{{ match.duration }}</p> |
||||
|
||||
</div> |
||||
{% else %} |
||||
<p class="center">No matches at the moment...</p> |
||||
{% endif %} |
||||
</div> |
||||
|
||||
|
||||
</html> |
||||
@ -1,12 +1,42 @@ |
||||
from django.shortcuts import render |
||||
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 |
||||
from .serializers import UserSerializer, MatchSerializer |
||||
from rest_framework import viewsets |
||||
from rest_framework import permissions |
||||
|
||||
def index(request): |
||||
matches = Match.objects.order_by('-court') |
||||
matches = Match.objects.order_by('court') |
||||
template = loader.get_template('scores/index.html') |
||||
context = { |
||||
'matches': matches, |
||||
} |
||||
return HttpResponse(template.render(context, request)) |
||||
|
||||
def match(request, match_id): |
||||
|
||||
match = get_object_or_404(Match, pk=match_id) |
||||
template = loader.get_template('scores/match.html') |
||||
context = { |
||||
'match': match, |
||||
} |
||||
return HttpResponse(template.render(context, request)) |
||||
|
||||
|
||||
class UserViewSet(viewsets.ModelViewSet): |
||||
""" |
||||
API endpoint that allows users to be viewed or edited. |
||||
""" |
||||
queryset = User.objects.all().order_by('-date_joined') |
||||
serializer_class = UserSerializer |
||||
permission_classes = [permissions.IsAuthenticated] |
||||
|
||||
class MatchViewSet(viewsets.ModelViewSet): |
||||
""" |
||||
API endpoint that allows matches to be viewed or edited. |
||||
""" |
||||
queryset = Match.objects.all().order_by('court') |
||||
serializer_class = MatchSerializer |
||||
permission_classes = [permissions.IsAuthenticated] |
||||
|
||||
Loading…
Reference in new issue