Compare commits

..

1 Commits

Author SHA1 Message Date
Nicolas Ferrari 3a54e398e4 Tournament stream 2 years ago
  1. 13
      padelclub_backend/settings.py
  2. 13
      padelclub_backend/settings_app.py
  3. 3
      padelclub_backend/urls.py
  4. 19
      tournaments/migrations/0011_alter_teamstate_score.py
  5. 18
      tournaments/migrations/0012_alter_teamstate_score.py
  6. 19
      tournaments/migrations/0013_teamstate_team_registration.py
  7. 19
      tournaments/migrations/0014_alter_teamstate_team_registration.py
  8. 95
      tournaments/models.py
  9. 1
      tournaments/serializers.py
  10. 33
      tournaments/templates/tournaments/match_cell.html
  11. 26
      tournaments/templates/tournaments/matches.html

@ -106,6 +106,18 @@ AUTH_PASSWORD_VALIDATORS = [
}, },
] ]
REST_FRAMEWORK = {
# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
],'DEFAULT_PERMISSION_CLASSES': [
# 'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
'rest_framework.permissions.IsAdminUser',
]
}
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/4.1/topics/i18n/ # https://docs.djangoproject.com/en/4.1/topics/i18n/
@ -143,4 +155,3 @@ REST_FRAMEWORK = {
} }
from .settings_local import * from .settings_local import *
from .settings_app import *

@ -1,13 +0,0 @@
# Rest Framework configuration
REST_FRAMEWORK = {
# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
# 'DEFAULT_PERMISSION_CLASSES': [
# 'rest_framework.permissions.IsAuthenticated',
# ],
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.TokenAuthentication',
]
}

@ -13,7 +13,6 @@ Including another URLconf
1. Import the include() function: from django.urls import include, path 1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
""" """
from posixpath import basename
from django.contrib import admin from django.contrib import admin
from django.urls import include, path from django.urls import include, path
from rest_framework import routers from rest_framework import routers
@ -30,7 +29,7 @@ router.register(r'matches', views.MatchViewSet)
router.register(r'team-states', views.TeamStateViewSet) router.register(r'team-states', views.TeamStateViewSet)
router.register(r'team-registrations', views.TeamRegistrationViewSet) router.register(r'team-registrations', views.TeamRegistrationViewSet)
router.register(r'player-registrations', views.PlayerRegistrationViewSet) router.register(r'player-registrations', views.PlayerRegistrationViewSet)
router.register(r'exp-tournaments', views.ExpandedTournamentViewSet, basename='tournaments-json') router.register(r'exp-tournaments', views.ExpandedTournamentViewSet)
urlpatterns = [ urlpatterns = [
path('api/', include(router.urls)), path('api/', include(router.urls)),

@ -1,19 +0,0 @@
# Generated by Django 4.2.11 on 2024-03-08 11:09
import django.contrib.postgres.fields
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('tournaments', '0010_alter_groupstage_tournament_alter_round_tournament'),
]
operations = [
migrations.AlterField(
model_name='teamstate',
name='score',
field=django.contrib.postgres.fields.ArrayField(base_field=models.IntegerField(), blank=True, null=True, size=None),
),
]

@ -1,18 +0,0 @@
# Generated by Django 4.2.11 on 2024-03-08 11:40
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('tournaments', '0011_alter_teamstate_score'),
]
operations = [
migrations.AlterField(
model_name='teamstate',
name='score',
field=models.CharField(blank=True, max_length=50, null=True),
),
]

@ -1,19 +0,0 @@
# Generated by Django 4.2.11 on 2024-03-08 13:38
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('tournaments', '0012_alter_teamstate_score'),
]
operations = [
migrations.AddField(
model_name='teamstate',
name='team_registration',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='tournaments.match'),
),
]

@ -1,19 +0,0 @@
# Generated by Django 4.2.11 on 2024-03-08 13:42
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('tournaments', '0013_teamstate_team_registration'),
]
operations = [
migrations.AlterField(
model_name='teamstate',
name='team_registration',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='tournaments.teamregistration'),
),
]

@ -4,7 +4,6 @@ from django.contrib.auth.models import AbstractUser
from django.conf import settings from django.conf import settings
import uuid import uuid
import os import os
from django.utils import timezone
from django.utils.encoding import Promise from django.utils.encoding import Promise
@ -255,64 +254,6 @@ class Match(models.Model):
return "no date" return "no date"
# return str(self.start_date) #.strftime("%H:%M") # return str(self.start_date) #.strftime("%H:%M")
def current_duration(self):
if self.end_date:
return (self.end_date - self.start_date).total_seconds()
else:
return (timezone.now() - self.start_date).total_seconds()
def durationPrefix(self):
if self.current_duration() > 0:
return "Temps de jeu"
else:
return "Démarrage prévu dans"
def formatted_duration(self):
_seconds = self.current_duration()
if _seconds > 0:
_hours = int(_seconds / 3600)
_minutes = int((_seconds % 3600) / 60)
return f"{_hours:02d}h{_minutes:02d}min"
else :
_seconds = _seconds * -1
_hours = int(_seconds / 3600)
_minutes = int((_seconds % 3600) / 60)
return f"{_hours:02d}h{_minutes:02d}min"
# def seconds(self):
# return (timezone.now() - self.start_date).total_seconds()
def live_match(self):
title = f"{self.index}"
date = self.formatted_start_date()
duration = self.formatted_duration()
livematch = LiveMatch(title, date, duration)
for team_state in self.team_states:
image = team_state.team_registration.logo
names = team_state.team_names()
scores = team_state.score
weight = team_state.weight
is_winner = False
team = Team(image, names, scores, weight, is_winner)
break
# def __init__(self, image, names, scores, weight, is_winner):
# def __init__(self, title, date, teams, duration):
class TeamRegistration(models.Model): class TeamRegistration(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
tournament = models.ForeignKey(Tournament, on_delete=models.CASCADE) tournament = models.ForeignKey(Tournament, on_delete=models.CASCADE)
@ -381,7 +322,6 @@ class TeamState(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
match = models.ForeignKey(Match, on_delete=models.CASCADE, related_name="team_states") match = models.ForeignKey(Match, on_delete=models.CASCADE, related_name="team_states")
player_registrations = models.ManyToManyField(PlayerRegistration, blank=True) player_registrations = models.ManyToManyField(PlayerRegistration, blank=True)
team_registration = models.ForeignKey(TeamRegistration, on_delete=models.CASCADE, null=True, blank=True)
score = models.CharField(max_length=50, null=True, blank=True) score = models.CharField(max_length=50, null=True, blank=True)
walk_out = models.IntegerField(null=True, blank=True) #id, int of the walked_out team walk_out = models.IntegerField(null=True, blank=True) #id, int of the walked_out team
lucky_loser = models.BooleanField() lucky_loser = models.BooleanField()
@ -393,36 +333,13 @@ class TeamState(models.Model):
names = map(lambda player: player.name(), self.player_registrations.all()) names = map(lambda player: player.name(), self.player_registrations.all())
return " - ".join(names) return " - ".join(names)
def team_names(self): # class StageCall:
names = [] # def __init__(self, stage):
if self.team_registration.name: # self.stage = stage
names.append(self.team_registration.name) # self.team_calls = []
else:
names = self.player_names()
class Team:
def __init__(self, image, names, scores, weight, is_winner):
self.image = image
self.names = []
self.scores = []
self.weight = weight
self.is_winner = is_winner
def add_names(self, name):
self.names.append(name)
def add_set_score(self, score):
self.scores.append(score)
class LiveMatch:
def __init__(self, title, date, duration):
self.title = title
self.date = date
self.teams = []
self.duration = duration
def add_team(self, team): # def add_team(self, team_call):
self.teams.append(team) # self.team_calls.append(team_call)
class TeamCall: class TeamCall:
def __init__(self, names, date, weight, stage, image): def __init__(self, names, date, weight, stage, image):

@ -138,7 +138,6 @@ class ExpandedGroupStageSerializer(serializers.HyperlinkedModelSerializer):
class ExpandedTeamRegistrationSerializer(serializers.HyperlinkedModelSerializer): class ExpandedTeamRegistrationSerializer(serializers.HyperlinkedModelSerializer):
playerregistration_set = PlayerRegistrationSerializer(many=True, read_only=True) playerregistration_set = PlayerRegistrationSerializer(many=True, read_only=True)
call_date = serializers.DateTimeField(format='%H:%M')
class Meta: class Meta:
# match_id = serializers.PrimaryKeyRelatedField(queryset=Match.objects.all()) # match_id = serializers.PrimaryKeyRelatedField(queryset=Match.objects.all())
group_stage_id = serializers.PrimaryKeyRelatedField(queryset=GroupStage.objects.all()) group_stage_id = serializers.PrimaryKeyRelatedField(queryset=GroupStage.objects.all())

@ -1,33 +0,0 @@
<div class="bubble">
<div class="flex-row">
<label class="left-label matchtitle">{{ match.title }}</label>
<label class="right-label info">{{ match.formatted_start_date }}</label>
</div>
<div>
{% for team in match.teams %}
<div class="test bottom-border padding-bottom-small">
<div class="left-label">
{% for name in team.names %}
<div class="winner">
{{ name }}
</div>
{% endfor %}
</div>
<div class="">
{% for score in team.scores %}
<span class="score ws {% if team.is_winner %}winner{% endif %}">{{ score }}</span>
{% endfor %}
</div>
</div>
{% endfor %}
</div>
<div class="top-margin flex-row">
<label class="left-label minor-info">{{ match.duration }}</label>
<!-- <a href="" class="right-label">détails</a> -->
</div>
</div>

@ -1,26 +0,0 @@
{% extends 'tournaments/base.html' %}
{% block head_title %}Matchs{% endblock %}
{% block title %}Matchs{% endblock %}
{% block content %}
{% if matches %}
<div class="grid-x">
<div class="cell medium-6 large-6 topblock my-block">
{% if matches %}
{% for match in matches %}
{% include 'tournaments/match_cell.html' %}
{% endfor %}
{% endif %}
</div>
</div>
{% endif %}
{% endblock %}
Loading…
Cancel
Save