From 8e9b4b8aa7aefe8678ebd2610af103d772105b3e Mon Sep 17 00:00:00 2001 From: Fred Pauchet Date: Mon, 4 Oct 2021 21:46:09 +0200 Subject: [PATCH] Rewrite templatetags --- khana/people/templatetags/accident.py | 4 +-- khana/people/templatetags/chrono.py | 33 ------------------- khana/people/templatetags/event.py | 29 ----------------- khana/people/templatetags/format.py | 13 ++++---- khana/people/templatetags/plannification.py | 11 +++---- khana/people/templatetags/planning.py | 36 --------------------- khana/people/templatetags/routines.py | 16 --------- khana/people/templatetags/scores.py | 25 -------------- khana/people/templatetags/statistics.py | 9 +++--- khana/people/templatetags/training.py | 13 ++++---- 10 files changed, 22 insertions(+), 167 deletions(-) delete mode 100644 khana/people/templatetags/chrono.py delete mode 100644 khana/people/templatetags/event.py delete mode 100644 khana/people/templatetags/planning.py delete mode 100644 khana/people/templatetags/routines.py delete mode 100644 khana/people/templatetags/scores.py diff --git a/khana/people/templatetags/accident.py b/khana/people/templatetags/accident.py index 102a350..fad9ec3 100644 --- a/khana/people/templatetags/accident.py +++ b/khana/people/templatetags/accident.py @@ -1,9 +1,9 @@ -# coding=utf-8 from django.shortcuts import get_object_or_404 -from people.models import Gymnast, Accident from django import template +from khana.people.models import Gymnast, Accident + register = template.Library() diff --git a/khana/people/templatetags/chrono.py b/khana/people/templatetags/chrono.py deleted file mode 100644 index c7082bc..0000000 --- a/khana/people/templatetags/chrono.py +++ /dev/null @@ -1,33 +0,0 @@ -# coding=utf-8 - -from django.db.models import Count -from django.shortcuts import get_object_or_404 -from people.models import Gymnast, CanDoRelation -from objective.models import Chrono - -from django import template - -register = template.Library() - -# PLUS UTILISE !!!! -@register.inclusion_tag("gymnast_chrono.html") -def display_chrono(gymnastid): - """ - Selectionne tous les chosos réalisé par le gymnaste - """ - - chrono_list = Chrono.objects.filter(gymnast=gymnastid).order_by("date") - chrono_10c = chrono_list.filter(routine_type=0) - chrono_r1 = chrono_list.filter(routine_type=1) - chrono_r2 = chrono_list.filter(routine_type=2) - chrono_rf = chrono_list.filter(routine_type=3) - - context = { - "chrono_list": chrono_list, - "chrono_10c": chrono_10c, - "chrono_r1": chrono_r1, - "chrono_r2": chrono_r2, - "chrono_rf": chrono_rf, - "gymnastid": gymnastid, - } - return context diff --git a/khana/people/templatetags/event.py b/khana/people/templatetags/event.py deleted file mode 100644 index 6ec6a73..0000000 --- a/khana/people/templatetags/event.py +++ /dev/null @@ -1,29 +0,0 @@ -# coding=UTF-8 - -from django.shortcuts import get_object_or_404 -from django import template -from datetime import date -from people.models import Gymnast -from planning.models import ( - Event, - get_number_of_weeks_between, -) -import pendulum - -register = template.Library() - -# PLUS UTILISE !!!! -@register.inclusion_tag("gymnast_event.html") -def display_event(gymnastid): - """ - Renvoie deux listes d'évènements : ceux à venir et ceux passés. - """ - today = pendulum.now().date() - next_event_list = Event.objects.filter(gymnasts=gymnastid, datebegin__gte=today) - previous_event_list = Event.objects.filter(gymnasts=gymnastid, datebegin__lte=today) - - context = { - "next_event_list": next_event_list, - "previous_event_list": previous_event_list, - } - return context diff --git a/khana/people/templatetags/format.py b/khana/people/templatetags/format.py index 87257a5..1509ab7 100644 --- a/khana/people/templatetags/format.py +++ b/khana/people/templatetags/format.py @@ -1,4 +1,3 @@ -# coding=utf-8 from django import template @@ -7,15 +6,15 @@ register = template.Library() @register.filter def format_number(phone_number): - """ - Mise en forme des numéros de GSM pour respecter le format xxxx/xx.xx.xx. + """Mise en forme des numéros de GSM pour respecter le format xxxx/xx.xx.xx. - Si le numéro passé en paramètre est vide ou si le nombre de caractères - le composant est inférieur à 10, une valeur vide est retournée. + Returns: + Si le numéro passé en paramètre est vide ou si le nombre de caractères + le composant est inférieur à 10, une valeur vide est retournée. """ if phone_number and len(phone_number) == 10: return "{0}/{1}.{2}.{3}".format( phone_number[:4], phone_number[4:6], phone_number[6:8], phone_number[8:10] ) - else: - return "" + + return "" diff --git a/khana/people/templatetags/plannification.py b/khana/people/templatetags/plannification.py index 507098c..d285dd6 100644 --- a/khana/people/templatetags/plannification.py +++ b/khana/people/templatetags/plannification.py @@ -1,15 +1,12 @@ # coding=utf-8 from django.shortcuts import get_object_or_404 -from people.models import Gymnast - -# from people.models import Gymnast, ToDoRelation -from objective.models import Skill - -# from planning.models import Event - from django import template +from khana.eople.models import Gymnast + +from khana.objective.models import Skill + register = template.Library() diff --git a/khana/people/templatetags/planning.py b/khana/people/templatetags/planning.py deleted file mode 100644 index 2df3916..0000000 --- a/khana/people/templatetags/planning.py +++ /dev/null @@ -1,36 +0,0 @@ -# coding=UTF-8 - -from people.models import Gymnast -from planning.models import PlanningLine -from datetime import date -from django.db import connection -from django import template - -register = template.Library() - - -@register.inclusion_tag("gymnast_program.html") -def display_planningline(gymnastid): - """ - Selectionne tous les chosos réalisé par le gymnaste - """ - pass - # # 1) obtenir la date d'aujourd'hui - # today = date.today() - - # # 2) obtenir LA première date en db SUPERIEURE à la date du jour ainsi que - # # LA première date en db INFERIEURE à la date du jour. - # previous_date = PlanningLine.objects.values_list('date', flat=True).filter(date__lte=today).order_by('-date').first() - # next_date = PlanningLine.objects.values_list('date', flat=True).filter(date__gte=today).order_by('date').first() - - # if previous_date is None: - # previous_date = today - - # if next_date is None: - # next_date = today - - # # 3) récupérer les records du gymnaste passé en paramètre ainsi que pour les dates récupérées. - # line_list = PlanningLine.objects.filter(date__range=(previous_date, next_date), gymnast=gymnastid).order_by('order') - - # context = {'line_list': line_list, 'gymnastid': gymnastid} - # return context diff --git a/khana/people/templatetags/routines.py b/khana/people/templatetags/routines.py deleted file mode 100644 index acac55f..0000000 --- a/khana/people/templatetags/routines.py +++ /dev/null @@ -1,16 +0,0 @@ -# coding=UTF-8 - -from people.models import Gymnast, GymnastHasRoutine -from django import template - -register = template.Library() - -# N'EST PUS UTILISE !!! -@register.inclusion_tag("gymnast_routine.html") -def display_routines(gymnast): - """ - Tag affichant les séries d'un gymnaste. - """ - ghr_list = gymnast.has_routine.prefetch_related("routine") - context = {"ghr_list": ghr_list, "gymnastid": gymnast.id} - return context diff --git a/khana/people/templatetags/scores.py b/khana/people/templatetags/scores.py deleted file mode 100644 index df2bad9..0000000 --- a/khana/people/templatetags/scores.py +++ /dev/null @@ -1,25 +0,0 @@ -# coding=UTF-8 - -from competition.models import Point -from django import template - -register = template.Library() - -# PLUS UTILISE !!! -@register.inclusion_tag("gymnast_scores.html") -def display_score(gymnastid): - """ - Selectionne tous les scores réalisés par le gymnaste - """ - score_list = Point.objects.filter(gymnast=gymnastid).order_by("-event__datebegin") - score_routine1_list = score_list.filter(routine_type=0) - score_routine2_list = score_list.filter(routine_type=1) - score_routine3_list = score_list.filter(routine_type=2) - context = { - "score_list": score_list, - "gymnastid": gymnastid, - "score_routine1_list": score_routine1_list, - "score_routine2_list": score_routine2_list, - "score_routine3_list": score_routine3_list, - } - return context diff --git a/khana/people/templatetags/statistics.py b/khana/people/templatetags/statistics.py index 2c7f62e..4eac9ee 100644 --- a/khana/people/templatetags/statistics.py +++ b/khana/people/templatetags/statistics.py @@ -1,11 +1,10 @@ -# coding=UTF-8 +from django import template from django.db.models import Count, Min from django.shortcuts import get_object_or_404 -from people.models import Gymnast, CanDoRelation -from objective.models import Educative, Skill -from django.db.models import Min -from django import template + +from khana.people.models import Gymnast, CanDoRelation +from khana.objective.models import Educative, Skill register = template.Library() diff --git a/khana/people/templatetags/training.py b/khana/people/templatetags/training.py index 837b12a..36d476a 100644 --- a/khana/people/templatetags/training.py +++ b/khana/people/templatetags/training.py @@ -1,14 +1,13 @@ -# coding=UTF-8 - -from django.db.models import Count -from django.shortcuts import get_object_or_404 -from people.models import Gymnast, CanDoRelation -from objective.models import Educative, Skill -from planning.models import Round, Training from datetime import date from django import template +from django.db.models import Count +from django.shortcuts import get_object_or_404 + +from khana.people.models import Gymnast, CanDoRelation +from khana.objective.models import Educative, Skill +from khana.planning.models import Round, Training register = template.Library()