diff --git a/padel/settings.py b/padel/settings.py index fdddac8..36dc097 100644 --- a/padel/settings.py +++ b/padel/settings.py @@ -37,7 +37,8 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', - 'scores' + 'scores', + 'rest_framework' ] MIDDLEWARE = [ @@ -100,6 +101,15 @@ AUTH_PASSWORD_VALIDATORS = [ }, ] +# Rest + +REST_FRAMEWORK = { + # Use Django's standard `django.contrib.auth` permissions, + # or allow read-only access for unauthenticated users. + 'DEFAULT_PERMISSION_CLASSES': [ + 'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly' + ] +} # Internationalization # https://docs.djangoproject.com/en/4.1/topics/i18n/ diff --git a/padel/urls.py b/padel/urls.py index 6d79dd2..6f70383 100644 --- a/padel/urls.py +++ b/padel/urls.py @@ -15,8 +15,16 @@ Including another URLconf """ from django.contrib import admin from django.urls import include, path +from rest_framework import routers +from scores import views + +router = routers.DefaultRouter() +router.register(r'users', views.UserViewSet) +router.register(r'matches', views.MatchViewSet) urlpatterns = [ + path('api/', include(router.urls)), path('', include('scores.urls')), path('admin/', admin.site.urls), + path('api-auth/', include('rest_framework.urls', namespace='rest_framework')) ] diff --git a/scores/migrations/0005_match_team5.py b/scores/migrations/0005_match_team5.py new file mode 100644 index 0000000..433ca0d --- /dev/null +++ b/scores/migrations/0005_match_team5.py @@ -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), + ), + ] diff --git a/scores/models.py b/scores/models.py index 039a9ca..5eaa339 100644 --- a/scores/models.py +++ b/scores/models.py @@ -1,6 +1,5 @@ from django.db import models -import datetime -from datetime import timedelta +from django.utils import timezone class Club(models.Model): name = models.CharField(max_length=200) @@ -18,6 +17,7 @@ class Match(models.Model): team2 = models.CharField(max_length=200, blank=True) team3 = models.CharField(max_length=200, blank=True) team4 = models.CharField(max_length=200, blank=True) + team5 = models.CharField(max_length=200, blank=True) team1scorecolumn1 = models.CharField(max_length=200, blank=True) team1scorecolumn2 = models.CharField(max_length=200, blank=True) @@ -30,6 +30,19 @@ class Match(models.Model): team2scorecolumn4 = models.CharField(max_length=200, blank=True) team2scorecolumn5 = models.CharField(max_length=200, blank=True) - # def duration(self): - # delta = datetime.now().date() - date - # return str(timedelta(delta)) + def duration(self): + + _seconds = (timezone.now() - self.date).total_seconds() + + if _seconds > 0: + _hours = int(_seconds / 3600) + _minutes = int((_seconds % 3600) / 60) + return f"{_hours}:{_minutes:02d}" + else : + _seconds = _seconds * -1 + _hours = int(_seconds / 3600) + _minutes = int((_seconds % 3600) / 60) + return "Démarre dans " + f"{_hours}:{_minutes:02d}" + "..." + + def seconds(self): + return (timezone.now() - self.date).total_seconds() diff --git a/scores/serializers.py b/scores/serializers.py new file mode 100644 index 0000000..bbaeef5 --- /dev/null +++ b/scores/serializers.py @@ -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'] diff --git a/scores/static/scores/style.css b/scores/static/scores/style.css index f34f9a2..1b1b509 100644 --- a/scores/static/scores/style.css +++ b/scores/static/scores/style.css @@ -1,16 +1,19 @@ -a { + +html { + /* font-size: 30px; /* px signifie 'pixels': la taille de base pour la police est désormais 10 pixels de haut */ + /* font-family: 'Open Sans', sans-serif; /* cela devrait être le reste du résultat obtenu à partir de Google fonts */ + + font-family: Helvetica, sans-serif; + background-color: #3878D8; color: white; } -html { - font-size: 30px; /* px signifie 'pixels': la taille de base pour la police est désormais 10 pixels de haut */ - font-family: 'Open Sans', sans-serif; /* cela devrait être le reste du résultat obtenu à partir de Google fonts */ - background-color: #438FFF; +a { color: white; } table { - font-size: 40px; /* px signifie 'pixels': la taille de base pour la police est désormais 10 pixels de haut */ + font-size: 30px; /* px signifie 'pixels': la taille de base pour la police est désormais 10 pixels de haut */ font-weight: 600; } @@ -20,22 +23,53 @@ table, th, td { border-collapse: collapse; } +tr { + height: 80px; +} + td { padding: 10px; } .score { - width: 50px; + width: 60px; text-align: center; vertical-align: middle; } +.center { + text-align: center; + margin: 0 auto; +} + .match { /* display: inline-block; */ - /* background-color: red; */ + display:inline-block; + width: 45%; + padding: 20px; + +} +.smatch { + padding-top: 100px; + width: 800px; + margin: 0 auto; + + /* position: relative; + top: 20%; */ + /* transform: translateY(50%); */ +} + +.right { + text-align: right; } +.scontainer { + display: flex; + align-items: center; +} + .container { /* width: 100%; */ + /* text-align:center; */ /* margin: 0 auto; */ } diff --git a/scores/templates/scores/index.html b/scores/templates/scores/index.html index d2ba35a..f6c7e2f 100644 --- a/scores/templates/scores/index.html +++ b/scores/templates/scores/index.html @@ -1,22 +1,75 @@ + + {% load static %} +
-| {{ match.team1 }} | + {% if match.team1scorecolumn1 %}{{ match.team1scorecolumn1 }} | {% endif %} +
| {{ match.team2 }} | + {% if match.team1scorecolumn2 %}{{ match.team1scorecolumn2 }} | {% endif %} +
| {{ match.team3 }} | + {% if match.team1scorecolumn3 %}{{ match.team1scorecolumn3 }} | {% endif %} +
| {{ match.team4 }} | + {% if match.team1scorecolumn4 %}{{ match.team1scorecolumn4 }} | {% endif %} +
| {{ match.team5 }} | + {% if match.team1scorecolumn5 %}{{ match.team1scorecolumn5 }} | {% endif %} +
| {{ match.team1scorecolumn4 }} | {% endif %} {% if match.team1scorecolumn5 %}{{ match.team1scorecolumn5 }} | {% endif %}||||
| {{ match.team2 }} | - {% if match.team2scorecolumn1 %}{{ match.team2scorecolumn1 }} | {% endif %} - {% if match.team2scorecolumn2 %}{{ match.team2scorecolumn2 }} | {% endif %} - {% if match.team2scorecolumn3 %}{{ match.team2scorecolumn3 }} | {% endif %} - {% if match.team2scorecolumn4 %}{{ match.team2scorecolumn4 }} | {% endif %} - {% if match.team2scorecolumn5 %}{{ match.team2scorecolumn5 }} | {% endif %} -
| {{ match.team2 }} | + {% if match.team2scorecolumn1 %}{{ match.team2scorecolumn1 }} | {% endif %} + {% if match.team2scorecolumn2 %}{{ match.team2scorecolumn2 }} | {% endif %} + {% if match.team2scorecolumn3 %}{{ match.team2scorecolumn3 }} | {% endif %} + {% if match.team2scorecolumn4 %}{{ match.team2scorecolumn4 }} | {% endif %} + {% if match.team2scorecolumn5 %}{{ match.team2scorecolumn5 }} | {% endif %} +
{{ match.duration }}
+No matches at the moment...
+Pas de matchs en cours...
{% endif %}COURS {{ match.court }}
+ +| {{ match.team1 }} | + {% if match.team1scorecolumn1 %}{{ match.team1scorecolumn1 }} | {% endif %} +
| {{ match.team2 }} | + {% if match.team1scorecolumn2 %}{{ match.team1scorecolumn2 }} | {% endif %} +
| {{ match.team3 }} | + {% if match.team1scorecolumn3 %}{{ match.team1scorecolumn3 }} | {% endif %} +
| {{ match.team4 }} | + {% if match.team1scorecolumn4 %}{{ match.team1scorecolumn4 }} | {% endif %} +
| {{ match.team5 }} | + {% if match.team1scorecolumn5 %}{{ match.team1scorecolumn5 }} | {% endif %} +
| {{ match.team1 }} | + {% if match.team1scorecolumn1 %}{{ match.team1scorecolumn1 }} | {% endif %} + {% if match.team1scorecolumn2 %}{{ match.team1scorecolumn2 }} | {% endif %} + {% if match.team1scorecolumn3 %}{{ match.team1scorecolumn3 }} | {% endif %} + {% if match.team1scorecolumn4 %}{{ match.team1scorecolumn4 }} | {% endif %} + {% if match.team1scorecolumn5 %}{{ match.team1scorecolumn5 }} | {% endif %} +
| {{ match.team2 }} | + {% if match.team2scorecolumn1 %}{{ match.team2scorecolumn1 }} | {% endif %} + {% if match.team2scorecolumn2 %}{{ match.team2scorecolumn2 }} | {% endif %} + {% if match.team2scorecolumn3 %}{{ match.team2scorecolumn3 }} | {% endif %} + {% if match.team2scorecolumn4 %}{{ match.team2scorecolumn4 }} | {% endif %} + {% if match.team2scorecolumn5 %}{{ match.team2scorecolumn5 }} | {% endif %} +
{{ match.duration }}
+ +No matches at the moment...
+{% endif %} +