diff --git a/jarvis/followup/views.py b/jarvis/followup/views.py index 2ae0bf0..b0508d9 100644 --- a/jarvis/followup/views.py +++ b/jarvis/followup/views.py @@ -6,6 +6,7 @@ from django.db.models import Q, Min, Avg, Max, Sum from django.urls import reverse from django.conf import settings from django.contrib.auth import get_user_model +from django.contrib.contenttypes.models import ContentType from django.core.mail import send_mail @@ -545,7 +546,10 @@ def chrono_create_or_update(request, chrono_id=None, gymnast_id=None): # notification gymnast = Gymnast.objects.get(pk=form.cleaned_data["gymnast"].id) - for notification in gymnast.notifications.filter(functionality=0): + functionality = ContentType.objects.get(model="chrono") + for notification in gymnast.notifications.filter( + functionality=functionality + ): send_mail( f"{gymnast} : Nouveau chrono", f"Un nouveau chrono enregistré pour {gymnast}", @@ -624,7 +628,10 @@ def learnedskill_create_or_update(request, gymnast_id=None): # notification gymnast = Gymnast.objects.get(pk=form.cleaned_data["gymnast"].id) - for notification in gymnast.notifications.filter(functionality=2): + functionality = ContentType.objects.get(model="learnedskill") + for notification in gymnast.notifications.filter( + functionality=functionality + ): send_mail( f"{gymnast} : Nouveau skill appris", f"Un nouveau skill a été appris par {gymnast}", @@ -677,7 +684,10 @@ def score_create_or_update(request, score_id=None, gymnast_id=None): # notification gymnast = Gymnast.objects.get(pk=form.cleaned_data["gymnast"].id) - for notification in gymnast.notifications.filter(functionality=4): + functionality = ContentType.objects.get(model="point") + for notification in gymnast.notifications.filter( + functionality=functionality + ): send_mail( f"{gymnast} : Nouveau score enregistré", f"Un nouveau score a été enregistré pour {gymnast}", @@ -797,7 +807,10 @@ def accident_create_or_update(request, accident_id=None, gymnast_id=None): # notification gymnast = Gymnast.objects.get(pk=form.cleaned_data["gymnast"].id) - for notification in gymnast.notifications.filter(functionality=1): + functionality = ContentType.objects.get(model="accident") + for notification in gymnast.notifications.filter( + functionality=functionality + ): send_mail( f"{gymnast} : Nouvel accident enregistré", f"Un nouvel accident enregistré pour {gymnast}", @@ -879,7 +892,10 @@ def mindstate_create_or_update( # notification gymnast = Gymnast.objects.get(pk=form.cleaned_data["gymnast"].id) - for notification in gymnast.notifications.filter(functionality=5): + functionality = ContentType.objects.get(model="mindstate") + for notification in gymnast.notifications.filter( + functionality=functionality + ): send_mail( f"{gymnast} : Nouvel état d'esprit enregistré", f"Un nouvel état d'esprit enregistré pour {gymnast}", @@ -961,7 +977,10 @@ def heightweight_create_or_update(request, heightweight_id=None, gymnast_id=None # notification gymnast = Gymnast.objects.get(pk=form.cleaned_data["gymnast"].id) - for notification in gymnast.notifications.filter(functionality=8): + functionality = ContentType.objects.get(model="heightweight") + for notification in gymnast.notifications.filter( + functionality=functionality + ): send_mail( f"{gymnast} : Nouveau poids/taille enregistré", f"Un nouveau poids/taille enregistré pour {gymnast}", @@ -1052,7 +1071,7 @@ def increment_routinedone(request): @login_required @require_http_methods(["GET", "POST"]) def routinedone_create_or_update(request, routinedone_id=None, gymnast_id=None): - """Création ou modification d'un chrono""" + """Création ou modification d'un nombre de série tentée.""" if routinedone_id: routinedone = get_object_or_404(NumberOfRoutineDone, pk=routinedone_id) @@ -1089,7 +1108,10 @@ def routinedone_create_or_update(request, routinedone_id=None, gymnast_id=None): # notification gymnast = Gymnast.objects.get(pk=form.cleaned_data["gymnast"].id) - for notification in gymnast.notifications.filter(functionality=7): + functionality = ContentType.objects.get(model="numberofroutinedone") + for notification in gymnast.notifications.filter( + functionality=functionality + ): send_mail( f"{gymnast} : Nouvelle série comptabilisée", f"Nouvelle série comptabilisée pour {gymnast}", @@ -1158,7 +1180,10 @@ def plan_create_or_update(request, plan_id=None, gymnast_id=None, skill_id=None) # notification gymnast = Gymnast.objects.get(pk=form.cleaned_data["gymnast"].id) - for notification in gymnast.notifications.filter(functionality=7): + functionality = ContentType.objects.get(model="plan") + for notification in gymnast.notifications.filter( + functionality=functionality + ): send_mail( f"{gymnast} : Nouvelle série comptabilisée", f"Nouvelle série comptabilisée pour {gymnast}", @@ -1246,7 +1271,10 @@ def intensity_create_or_update(request, intensity_id=None, gymnast_id=None): # notification gymnast = Gymnast.objects.get(pk=form.cleaned_data["gymnast"].id) - for notification in gymnast.notifications.filter(functionality=10): + functionality = ContentType.objects.get(model="intensity") + for notification in gymnast.notifications.filter( + functionality=functionality + ): send_mail( f"{gymnast} : Nouvelle intensité", f"Une nouvelle note vous a été envoyée pour {gymnast}", @@ -1313,7 +1341,10 @@ def season_information_create_or_update( # notification gymnast = Gymnast.objects.get(pk=form.cleaned_data["gymnast"].id) - for notification in gymnast.notifications.filter(functionality=11): + functionality = ContentType.objects.get(model="seasoninformation") + for notification in gymnast.notifications.filter( + functionality=functionality + ): send_mail( f"{gymnast} : Nouvelle information de saison", f"Une nouvelle information de saison enregistrée pour {gymnast}", diff --git a/jarvis/profiles/templates/notification_update.html b/jarvis/profiles/templates/notification_update.html index b214fe2..17c258e 100644 --- a/jarvis/profiles/templates/notification_update.html +++ b/jarvis/profiles/templates/notification_update.html @@ -1,4 +1,5 @@ {% extends "listing.html" %} +{% load get_item %} {% block datacontent %}
@@ -25,7 +26,7 @@ {{ functionality }}
- +
{% endfor %} diff --git a/jarvis/profiles/views.py b/jarvis/profiles/views.py index 50dadde..4e66417 100644 --- a/jarvis/profiles/views.py +++ b/jarvis/profiles/views.py @@ -53,10 +53,9 @@ def notification_update(request): notification_dict = {} for gymnast in gymnast_list: - query = gymnast.notifications.filter(user=request.user) - # query = Notification.objects.filter( - # user=request.user, gymnast=gymnast - # ).values_list("functionality", flat=True) + query = gymnast.notifications.filter(user=request.user).values_list( + "functionality", flat=True + ) if query: notification_dict[gymnast.id] = query @@ -94,7 +93,7 @@ def notification_remove(request): Supprime une demande de notification """ gymnast_id = request.POST.get("gymnast_id", None) - functionnality_id = request.POST.get("functionnality_id", None) + functionnality_id = request.POST.get("functionality_id", None) try: Notification.objects.get(