From cef1893333cce4f3fc7d11b9d0d95e2be44abe4c Mon Sep 17 00:00:00 2001 From: Gregory Trullemans Date: Fri, 10 May 2024 20:53:02 +0100 Subject: [PATCH] Update dashboard for gymnast. --- .../core/templates/dashboard/dashboard.html | 56 +++++- jarvis/core/views.py | 171 +++++++++++------- jarvis/location/templates/places/list.html | 4 +- .../gymnasts/tabs/tab_notes_events.html | 2 +- static/css/jarvis.css | 4 + 5 files changed, 162 insertions(+), 75 deletions(-) diff --git a/jarvis/core/templates/dashboard/dashboard.html b/jarvis/core/templates/dashboard/dashboard.html index 52dd2a8..562e2ee 100644 --- a/jarvis/core/templates/dashboard/dashboard.html +++ b/jarvis/core/templates/dashboard/dashboard.html @@ -27,8 +27,8 @@

Hi {{ user.first_name }} !

-

Welcome to Jarvi v1.03 (last update : 9 may 2024). You can find the user manual here (in french).

-

This application is here to help coaches to manage the gymnasts (evolution, evaluation, routines, scores, …). This tool is not perfect so feel free to make improvement proposals, bug reports, … by sending me an email.

+

Welcome to Jarvi v1.0.4 (last update : 10 may 2024).

+

This application is designed to assist coaches in managing gymnasts' progress, evaluations, routines, scores, and more. While this tool isn't flawless, please feel free to submit improvement suggestions, bug reports, or any feedback by sending an email.

@@ -130,13 +130,53 @@

Your last profile update

-
    -
  1. Wellbeing: {{ wellbeing_last_update.0 |date:"j F Y" }}
  2. -
  3. Height/Weight: {{ height_weight_last_update.0 |date:"j F Y" }}
  4. -
  5. Intensity: {{ intensities_last_update.0 |date:"j F Y" }}
  6. +
      +
    1. Wellbeing: + {% if wellbeing_state %} + + {% endif %} + {{ wellbeing_last_record_date.0 |date:"j F Y" }} + {% if wellbeing_state %} + + {% endif %} +
    2. +
    3. Height/Weight: + {% if height_weight_state %} + + {% endif %} + {{ height_weight_last_record_date.0 |date:"j F Y" }} + {% if wellbeing_state %} + + {% endif %} +
    4. +
    5. Intensity: + {% if intensity_state %} + + {% endif %} + {{ intensities_last_record_date.0 |date:"j F Y" }} + {% if wellbeing_state %} + + {% endif %} +
    6. -
    7. Chrono: {{ chronos_last_update.0 |date:"j F Y" }}
    8. -
    9. Learned Skill: {{ known_skills_last_update.0 |date:"j F Y" }}
    10. +
    11. Chrono: + {% if chrono_state %} + + {% endif %} + {{ chrono_last_record_date.0 |date:"j F Y" }} + {% if chrono_state %} + + {% endif %} +
    12. +
    13. Learned Skill: + {% if known_skills_state %} + + {% endif %} + {{ known_skills_last_record_date.0 |date:"j F Y" }} + {% if known_skills_state %} + + {% endif %} +
{% endif %} diff --git a/jarvis/core/views.py b/jarvis/core/views.py index ac3b0dc..68e06cc 100644 --- a/jarvis/core/views.py +++ b/jarvis/core/views.py @@ -93,11 +93,31 @@ def next_birthdays(request, number_of_birthday): return birthday_list +def gymnast_have_birthday(request): + """ + Renvoie la liste des gymnastes qui ont leur anniversaire aujourd'hui. + """ + today = pendulum.now().date() + return Gymnast.objects.filter(birthdate__day=today.day, birthdate__month=today.month).values_list("id") + # @lru_cache() # def get_last_updated_gymnasts(expiration_date): # ... +# TODO: véririer si c'est l'anniversaire de la personne qui est connectée. +# TODO: check if gymnast have point +# --------------------------- +# 1. récupérer tous les évènements passés +# 2. pour chaque event, vérifier que tous les gymnastes renseignés +# dans les participants ont des points associés. +# S'il n'y a pas de point, faire une alerte à l'utilisateur qui se connecte. + +# TODO: Check if gymnast have update +# ----------------------------- +# lister tous les gymnastes qui n'ont pas eu d'update depuis... 2 semaines ? +# peut-être le paramètre (en jour) devrait être stocké en DB. +# S'il n'y a pas d'update, faire une alerte à l'utilisateur qui se connecte. @login_required @require_http_methods(["GET"]) def home(request): @@ -106,9 +126,21 @@ def home(request): """ today = timezone.now() # pendulum.now().date() _, week_number = from_date_to_week_number(today) - event_list = Event.objects.filter(date_begin__gte=today).order_by("date_begin")[:10] - quote = Citation.objects.order_by("?").first() + context = { + "week_number": week_number, + "quote": Citation.objects.order_by("?").first(), + "event_list": Event.objects.filter(date_begin__gte=today).order_by("date_begin")[:10], + "nb_active_gymnast": Gymnast.objects.filter(is_active=True).count(), + "nb_trainer": User.objects.filter(is_active=True, groups__name="trainer").count(), + "nb_event": Event.objects.all().count(), + "nb_skill": Skill.objects.all().count(), + "nb_routine": Routine.objects.all().count(), + "nb_score": Point.objects.all().count(), + "nb_club": Club.objects.all().count(), + "percentage_week": (week_number / 52) * 100, + "birthday_list": next_birthdays(request, 10), + } is_trainer = request.user.groups.filter(name="trainer").exists() if is_trainer: @@ -150,75 +182,86 @@ def home(request): ) .distinct() ) - wellbeing_last_update = None - height_weight_last_update = None - intensities_last_update = None - # points_last_update = None - chronos_last_update = None - known_skills_last_update = None + + context["is_trainer"] = is_trainer + context["last_updated_gymnasts"] = last_updated_gymnasts + context["waiting_update_gymnast"] = waiting_update_gymnast + else: + todate = pendulum.now().date() + birthday_list = gymnast_have_birthday(request) gymnast = get_object_or_404(Gymnast, pk=request.user.gymnast.id) - last_updated_gymnasts = None - waiting_update_gymnast = None - wellbeing_last_update = WellBeing.objects.filter(gymnast=gymnast).values_list("date").order_by("-date").first() - height_weight_last_update = HeightWeight.objects.filter(gymnast=gymnast).values_list("date").order_by("-date").first() - intensities_last_update = Intensity.objects.filter(gymnast=gymnast).values_list("date").order_by("-date").first() + + # if birthday_list is not None and gymnast.id in birthday_list: + # print("C'est l'anniversaire du gymnaste !") + # else: + # print("Pas son annif…") + + wellbeing_last_record_date = WellBeing.objects.filter(gymnast=gymnast).values_list("date").order_by("-date").first() + + if todate.diff(wellbeing_last_record_date[0]).in_days() > 21: + wellbeing_state = "danger bold" + elif todate.diff(wellbeing_last_record_date[0]).in_days() > 14: + wellbeing_state = "danger" + elif todate.diff(wellbeing_last_record_date[0]).in_days() > 7: + wellbeing_state = "warning" + else: + wellbeing_state = None + + height_weight_last_record_date = HeightWeight.objects.filter(gymnast=gymnast).values_list("date").order_by("-date").first() + if todate.diff(height_weight_last_record_date[0]).in_days() > 21: + height_weight_state = "danger bold" + elif todate.diff(height_weight_last_record_date[0]).in_days() > 14: + height_weight_state = "danger" + elif todate.diff(height_weight_last_record_date[0]).in_days() > 7: + height_weight_state = "warning" + else: + height_weight_state = None + + intensities_last_record_date = Intensity.objects.filter(gymnast=gymnast).values_list("date").order_by("-date").first() + if todate.diff(intensities_last_record_date[0]).in_days() > 21: + intensity_state = "danger bold" + elif todate.diff(intensities_last_record_date[0]).in_days() > 14: + intensity_state = "danger" + elif todate.diff(intensities_last_record_date[0]).in_days() > 7: + intensity_state = "warning" + else: + intensity_state = None + # points_last_update = Gymnast.objects.all().order_by("-date")[:1] - chronos_last_update = Chrono.objects.filter(gymnast=gymnast).values_list("date").order_by("-date").first() - known_skills_last_update = LearnedSkill.objects.filter(gymnast=gymnast).values_list("date").order_by("-date").first() + chrono_last_record_date = Chrono.objects.filter(gymnast=gymnast).values_list("date").order_by("-date").first() + if todate.diff(chrono_last_record_date[0]).in_days() > 21: + chrono_state = "danger bold" + elif todate.diff(chrono_last_record_date[0]).in_days() > 14: + chrono_state = "danger" + elif todate.diff(chrono_last_record_date[0]).in_days() > 7: + chrono_state = "warning" + else: + chrono_state = None - # TODO: véririer si c'est l'anniversaire de la personne qui est connectée. + known_skills_last_record_date = LearnedSkill.objects.filter(gymnast=gymnast).values_list("date").order_by("-date").first() + if todate.diff(known_skills_last_record_date[0]).in_days() > 21: + known_skills_state = "danger bold" + elif todate.diff(known_skills_last_record_date[0]).in_days() > 14: + known_skills_state = "danger" + elif todate.diff(known_skills_last_record_date[0]).in_days() > 7: + known_skills_state = "warning" + else: + known_skills_state = None - nb_active_gymnast = Gymnast.objects.filter(is_active=True).count() - nb_trainer = User.objects.filter(is_active=True, groups__name="trainer").count() - nb_event = Event.objects.all().count() - nb_skill = Skill.objects.all().count() - nb_routine = Routine.objects.all().count() - nb_score = Point.objects.all().count() - nb_club = Club.objects.all().count() - - percentage_week = (week_number / 52) * 100 - - birthday_list = next_birthdays(request, 10) - - # # check if gymnast have point - # # --------------------------- - # # 1. récupérer tous les évènements passés - # # 2. pour chaque event, vérifier que tous les gymnastes renseignés - # # dans les participants ont des points associés. - # # S'il n'y a pas de point, faire une alerte à l'utilisateur qui se connecte. - - # # Check if gymnast have update - # # ----------------------------- - # # lister tous les gymnastes qui n'ont pas eu d'update depuis... 2 semaines ? - # # peut-être le paramètre (en jour) devrait être stocké en DB. - # # S'il n'y a pas d'update, faire une alerte à l'utilisateur qui se connecte. - - context = { - "quote": quote, - "week_number": week_number, - "event_list": event_list, - "last_updated_gymnasts": last_updated_gymnasts, - "waiting_update_gymnast": waiting_update_gymnast, - "nb_active_gymnast": nb_active_gymnast, - "nb_trainer": nb_trainer, - "nb_event": nb_event, - "nb_skill": nb_skill, - "nb_routine": nb_routine, - "nb_score": nb_score, - "nb_club": nb_club, - "wellbeing_last_update": wellbeing_last_update, - "height_weight_last_update": height_weight_last_update, - "intensities_last_update": intensities_last_update, + context["wellbeing_last_record_date"] = wellbeing_last_record_date + context["wellbeing_state"] = wellbeing_state + context["height_weight_last_record_date"] = height_weight_last_record_date + context["height_weight_state"] = height_weight_state + context["intensities_last_record_date"] = intensities_last_record_date + context["intensity_state"] = intensity_state # "points_last_update": points_last_update, - "chronos_last_update": chronos_last_update, - "known_skills_last_update": known_skills_last_update, - "percentage_week": percentage_week, - "birthday_list": birthday_list, - "is_trainer": is_trainer, - } + context["chrono_last_record_date"] = chrono_last_record_date + context["chrono_state"] = chrono_state + context["known_skills_last_record_date"] = known_skills_last_record_date + context["known_skills_state"] = known_skills_state + return render(request, "dashboard/dashboard.html", context) - # return render(request, "dashboard/dashboard.html", {}) @login_required diff --git a/jarvis/location/templates/places/list.html b/jarvis/location/templates/places/list.html index 5b1c6e9..8d27fdc 100644 --- a/jarvis/location/templates/places/list.html +++ b/jarvis/location/templates/places/list.html @@ -28,9 +28,9 @@ {% if request.user|has_group:"trainer" %} {% endif %} - Name + Name Address - Zip + Zip City diff --git a/jarvis/people/templates/gymnasts/tabs/tab_notes_events.html b/jarvis/people/templates/gymnasts/tabs/tab_notes_events.html index c834248..634c2f8 100644 --- a/jarvis/people/templates/gymnasts/tabs/tab_notes_events.html +++ b/jarvis/people/templates/gymnasts/tabs/tab_notes_events.html @@ -41,7 +41,7 @@ -
+
{% if next_event_list %} diff --git a/static/css/jarvis.css b/static/css/jarvis.css index 63f2a3f..6a7ff97 100644 --- a/static/css/jarvis.css +++ b/static/css/jarvis.css @@ -95,6 +95,10 @@ textarea.form-control { font-size: 12px; } +.bold { + font-weight: bold; +} + .progress-bar-primary { background: #ba54f5; background-image: -webkit-linear-gradient(to bottom left, #ba54f5, #e14eca, #ba54f5);