add ranking website

main
Razmig Sarkissian 2 years ago
parent 65677db2a9
commit 83f5f1a4d5
  1. 18
      scores/migrations/0021_team_position_finale.py
  2. 5
      scores/models.py
  3. 2
      scores/serializers.py
  4. 120
      scores/templates/scores/ranks.html
  5. 19
      scores/templates/scores/teams.html
  6. 24
      scores/templates/scores/tournament.html
  7. 3
      scores/urls.py
  8. 19
      scores/views.py

@ -0,0 +1,18 @@
# Generated by Django 4.2 on 2023-07-31 11:34
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('scores', '0020_match_haswalkoutteam'),
]
operations = [
migrations.AddField(
model_name='team',
name='position_finale',
field=models.IntegerField(default=0),
),
]

@ -27,7 +27,9 @@ class Tournament(models.Model):
def teams(self):
return self.team_set.order_by('position')
def teamsByFinalRank(self):
return self.team_set.order_by('position_finale').filter(position_finale__gt=0)
class Match(models.Model):
tournament = models.ForeignKey(Tournament, on_delete=models.CASCADE, default=None)
date = models.DateTimeField('start date')
@ -115,6 +117,7 @@ class Team(models.Model):
name = models.CharField(max_length=200, blank=True)
rank = models.IntegerField(default=0)
position = models.IntegerField(default=0)
position_finale = models.IntegerField(default=0)
bracket = models.BooleanField(default=False)
position_label = models.CharField(max_length=200, blank=True)
date_label = models.CharField(max_length=200, blank=True)

@ -28,5 +28,5 @@ class MatchSerializer(serializers.HyperlinkedModelSerializer):
class TeamSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Team
fields = ['id', 'name', 'background_color', 'rank', 'position', 'bracket', 'position_label', 'date_label', 'tournament']
fields = ['id', 'name', 'background_color', 'rank', 'position', 'position_finale', 'bracket', 'position_label', 'date_label', 'tournament']

@ -0,0 +1,120 @@
<html>
{% load static %}
<head>
{% if tv %}
<script>history.scrollRestoration = "manual"</script>
<script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js">
</script>
{% endif %}
<link rel="stylesheet" href="{% static 'scores/style.css' %}">
<title>Padel</title>
</head>
{% if tv %}
<div class="wrapper" style="zoom:200%">
{% else %}
<div class="wrapper">
{% endif %}
{% if tv %}
<script>
var iInterval = 2000;
var iScrollInterval = 10000;
var iFadeInterval = 500;
var iScroll = $(document).height() - $(window).height();
if (iScroll * 10 + 4000 < 15000) {
iScrollInterval = 10000;
} else {
iScrollInterval = iScroll * 10;
}
var fade = function() {
$("body").fadeOut(iFadeInterval, function(){
$("html, body").scrollTop(0);
$("body").fadeIn(iFadeInterval,function(){
setTimeout(loop, iInterval);
});
});
}
var loop = function() {
var iScroll = $(document).height() - $(window).height();
if (iScroll * 10 + 4000 < 15000) {
iScrollInterval = 10000;
} else {
iScrollInterval = iScroll * 10;
}
$("html, body").animate({
scrollTop: iScroll
}, {
duration : iScrollInterval,
easing : "linear",
complete : function() {
setTimeout(fade, iInterval);
}
});
setTimeout(function(){
window.location.reload();
}, Math.max(iScrollInterval * 10 + 2000, 15000));
};
setTimeout(loop, iInterval);
</script>
{% endif %}
{% if tournament.club.header %}
{% if tv %}
<header class="scenter"><a href="/tv/club/{{ tournament.club.name }}/">{{ tournament.club.header }}</a></header>
{% else %}
<header class="scenter"><a href="/club/{{ tournament.club.name }}/">{{ tournament.club.header }}</a></header>
{% endif %}
{% endif %}
<main class="page-body">
{% autoescape off %}
<div class="scenter">
{% if tv %}
<h3><a href="tv/club/{{ tournament.club.name }}/tournoi/{{ tournament.id }}">{{ tournament.name }}</a>
{% else %}
<h3><a href="/club/{{ tournament.club.name }}/tournoi/{{ tournament.id }}">{{ tournament.name }}</a>
{% endif %}
</div>
<div class="scontainer">
<div class="teams">
<h1>Classement<h1>
<table>
<tr>
<th>Classement</th>
<th>Nom</th>
<th>Poids</th>
<th>Rang initial</th>
</tr>
{% for team in tournament.teamsByFinalRank %}
<tr height='100%' style="background-color:{{ team.background_color }};">
<td class="score">#{{ team.position_finale }}</td>
<td class="name" width='40%'>{{ team.name|linebreaksbr }}</td>
<td class="score">{{ team.rank }}</td>
<td class="name" width='20%'>{{ team.position }}</td>
</tr>
{% endfor %}
</table>
</div>
</div>
{% endautoescape %}
</main>
{% if tournament.club.footer %}
<footer class="page-footer, center">{{ tournament.club.footer }}</footer>
{% endif %}
</div>
</html>

@ -13,7 +13,6 @@
<link rel="stylesheet" href="{% static 'scores/style.css' %}">
<title>Padel</title>
<meta http-equiv="refresh" content="15"/>
</head>
{% if tv %}
<div class="wrapper" style="zoom:200%">
@ -27,7 +26,13 @@
var iInterval = 2000;
var iScrollInterval = 10000;
var iFadeInterval = 500;
var iScroll = $(document).height() - $(window).height();
if (iScroll * 10 + 4000 < 15000) {
iScrollInterval = 10000;
} else {
iScrollInterval = iScroll * 10;
}
var fade = function() {
$("body").fadeOut(iFadeInterval, function(){
$("html, body").scrollTop(0);
@ -39,6 +44,11 @@
var loop = function() {
var iScroll = $(document).height() - $(window).height();
if (iScroll * 10 + 4000 < 15000) {
iScrollInterval = 10000;
} else {
iScrollInterval = iScroll * 10;
}
$("html, body").animate({
scrollTop: iScroll
}, {
@ -48,9 +58,12 @@
setTimeout(fade, iInterval);
}
});
setTimeout(function(){
window.location.reload();
}, Math.max(iScrollInterval * 10 + 2000, 15000));
};
setTimeout(loop, iInterval);
</script>
</script>
{% endif %}
{% if tournament.club.header %}

@ -11,9 +11,11 @@
</script>
{% endif %}
<link rel="stylesheet" href="{% static 'scores/style.css' %}">
<title>Padel</title>
<meta http-equiv="refresh" content="15"/>
<link rel="stylesheet" href="{% static 'scores/style.css' %}">
<title>Padel</title>
{% if not tv %}
<meta http-equiv="refresh" content="15"/>
{% endif %}}
</head>
<div class="wrapper">
@ -23,7 +25,13 @@
var iInterval = 2000;
var iScrollInterval = 10000;
var iFadeInterval = 500;
var iScroll = $(document).height() - $(window).height();
if (iScroll * 10 + 4000 < 15000) {
iScrollInterval = 10000;
} else {
iScrollInterval = iScroll * 10;
}
var fade = function() {
$("body").fadeOut(iFadeInterval, function(){
$("html, body").scrollTop(0);
@ -35,6 +43,11 @@
var loop = function() {
var iScroll = $(document).height() - $(window).height();
if (iScroll * 10 + 4000 < 15000) {
iScrollInterval = 10000;
} else {
iScrollInterval = iScroll * 10;
}
$("html, body").animate({
scrollTop: iScroll
}, {
@ -44,6 +57,9 @@
setTimeout(fade, iInterval);
}
});
setTimeout(function(){
window.location.reload();
}, Math.max(iScrollInterval * 10 + 2000, 15000));
};
setTimeout(loop, iInterval);
</script>

@ -19,6 +19,9 @@ from django.urls import path
from . import views
urlpatterns = [
path('tv/club/<str:club_name>/<str:tournament_shortname>/classement/', views.tv_ranking, name='ranks'),
path('club/<str:club_name>/<str:tournament_shortname>/classement/', views.ranking, name='ranks'),
path('match/<int:match_id>/', views.match, name='match'),
path('tv/match/<int:match_id>/', views.match_tv, name='match'),

@ -186,6 +186,25 @@ def tv_teams_tournament(request, tournament_id):
}
return HttpResponse(template.render(context, request))
def tv_ranking(request, club_name, tournament_shortname):
club = get_object_or_404(Club, name__iexact=club_name.lower())
tournament = Tournament.objects.filter(club_id=club.id, shortname__iexact=tournament_shortname.lower()).first()
template = loader.get_template('scores/ranks.html')
context = {
'tournament': tournament,
'tv': True,
}
return HttpResponse(template.render(context, request))
def ranking(request, club_name, tournament_shortname):
club = get_object_or_404(Club, name__iexact=club_name.lower())
tournament = Tournament.objects.filter(club_id=club.id, shortname__iexact=tournament_shortname.lower()).first()
template = loader.get_template('scores/ranks.html')
context = {
'tournament': tournament,
}
return HttpResponse(template.render(context, request))
class UserViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows users to be viewed or edited.

Loading…
Cancel
Save