Rewrite templatetags

This commit is contained in:
Fred Pauchet 2021-10-04 21:46:09 +02:00
parent e56660e626
commit 8e9b4b8aa7
10 changed files with 22 additions and 167 deletions

View File

@ -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()

View File

@ -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

View File

@ -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

View File

@ -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 ""

View File

@ -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()

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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()

View File

@ -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()