From 6460ac5afc270c50775a94588a3dd6b1c6a34e0b Mon Sep 17 00:00:00 2001 From: Gregory Trullemans Date: Thu, 27 Apr 2023 11:23:05 +0200 Subject: [PATCH] First commit (without notification class) --- jarvis/profiles/admin.py | 22 +++--- .../profiles/migrations/0002_notification.py | 68 ---------------- jarvis/profiles/models.py | 22 +++--- jarvis/profiles/urls.py | 14 ++-- jarvis/profiles/views.py | 78 +++++++++---------- jarvis/tools/templatetags/get_item.py | 8 ++ 6 files changed, 76 insertions(+), 136 deletions(-) delete mode 100644 jarvis/profiles/migrations/0002_notification.py create mode 100644 jarvis/tools/templatetags/get_item.py diff --git a/jarvis/profiles/admin.py b/jarvis/profiles/admin.py index 2a30c5b..6d9bcd0 100644 --- a/jarvis/profiles/admin.py +++ b/jarvis/profiles/admin.py @@ -1,5 +1,5 @@ from django.contrib import admin -from .models import Profile, Notification +from .models import Profile from django_admin_listfilter_dropdown.filters import ( ChoiceDropdownFilter, RelatedDropdownFilter, @@ -12,16 +12,16 @@ class ProfileAdmin(admin.ModelAdmin): autocomplete_fields = ("user",) -class NotificationAdmin(admin.ModelAdmin): - model = Notification - list_display = ("user", "gymnast", "functionality") - autocomplete_fields = ("user", "gymnast") - list_filter = ( - ("user", RelatedDropdownFilter), - ("gymnast", RelatedDropdownFilter), - ("functionality", ChoiceDropdownFilter), - ) +# class NotificationAdmin(admin.ModelAdmin): +# model = Notification +# list_display = ("user", "gymnast", "functionality") +# autocomplete_fields = ("user", "gymnast") +# list_filter = ( +# ("user", RelatedDropdownFilter), +# ("gymnast", RelatedDropdownFilter), +# ("functionality", ChoiceDropdownFilter), +# ) admin.site.register(Profile, ProfileAdmin) -admin.site.register(Notification, NotificationAdmin) +# admin.site.register(Notification, NotificationAdmin) diff --git a/jarvis/profiles/migrations/0002_notification.py b/jarvis/profiles/migrations/0002_notification.py deleted file mode 100644 index 6267e76..0000000 --- a/jarvis/profiles/migrations/0002_notification.py +++ /dev/null @@ -1,68 +0,0 @@ -# Generated by Django 4.2 on 2023-04-23 06:42 - -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ("people", "0008_alter_gymnast_orientation"), - ("profiles", "0001_initial"), - ] - - operations = [ - migrations.CreateModel( - name="Notification", - fields=[ - ( - "id", - models.BigAutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ( - "functionality", - models.PositiveSmallIntegerField( - choices=[ - (0, "Chrono"), - (1, "Accident"), - (2, "LearnedSkill"), - (3, "Plan"), - (4, "Point"), - (5, "MindState"), - (6, "GymnastHasRoutine"), - (7, "NumberOfRoutineDone"), - (8, "HeightWeight"), - (9, "Note"), - (10, "Intensity"), - (11, "SeasonInformation"), - ] - ), - ), - ( - "gymnast", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - related_name="notifications", - to="people.gymnast", - ), - ), - ( - "user", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - to=settings.AUTH_USER_MODEL, - ), - ), - ], - options={ - "unique_together": {("user", "gymnast", "functionality")}, - }, - ), - ] diff --git a/jarvis/profiles/models.py b/jarvis/profiles/models.py index 9e14f2c..74ad838 100644 --- a/jarvis/profiles/models.py +++ b/jarvis/profiles/models.py @@ -58,17 +58,17 @@ class Profile(models.Model): return "%s %s" % (self.user.first_name, self.user.last_name) -class Notification(models.Model): - """Classe permettant de définir quelles notification un utilisateur veut recevoir.""" +# class Notification(models.Model): +# """Classe permettant de définir quelles notification un utilisateur veut recevoir.""" - class Meta: - unique_together = ("user", "gymnast", "functionality") +# class Meta: +# unique_together = ("user", "gymnast", "functionality") - user = models.ForeignKey(User, on_delete=models.CASCADE) - gymnast = models.ForeignKey( - Gymnast, on_delete=models.CASCADE, related_name="notifications" - ) - functionality = models.PositiveSmallIntegerField(choices=FUNCTIONALITY_CHOICES) +# user = models.ForeignKey(User, on_delete=models.CASCADE) +# gymnast = models.ForeignKey( +# Gymnast, on_delete=models.CASCADE, related_name="notifications" +# ) +# functionality = models.PositiveSmallIntegerField(choices=FUNCTIONALITY_CHOICES) - def __str__(self): - return f"{self.user} will be notified for add/update {self.functionality} to {self.gymnast}" +# def __str__(self): +# return f"{self.user} will be notified for add/update {self.functionality} to {self.gymnast}" diff --git a/jarvis/profiles/urls.py b/jarvis/profiles/urls.py index 0c7591b..890d211 100644 --- a/jarvis/profiles/urls.py +++ b/jarvis/profiles/urls.py @@ -7,11 +7,11 @@ from . import views profile_urlpatterns = [ path(r"edit/", views.profile_update, name="profile_update"), - path( - r"notification_update/", views.notification_update, name="notification_update" - ), - path(r"notification_add/", views.notification_add, name="notification_add"), - path( - r"notification_remove/", views.notification_remove, name="notification_remove" - ), + # path( + # r"notification_update/", views.notification_update, name="notification_update" + # ), + # path(r"notification_add/", views.notification_add, name="notification_add"), + # path( + # r"notification_remove/", views.notification_remove, name="notification_remove" + # ), ] diff --git a/jarvis/profiles/views.py b/jarvis/profiles/views.py index 128ddb3..3469fc7 100644 --- a/jarvis/profiles/views.py +++ b/jarvis/profiles/views.py @@ -8,7 +8,7 @@ from django.views.decorators.http import require_http_methods from django.urls import reverse from .forms import ProfileForm -from .models import Profile, Notification, FUNCTIONALITY_CHOICES +from .models import Profile # , Notification, FUNCTIONALITY_CHOICES from jarvis.people.models import Gymnast @@ -44,50 +44,50 @@ def profile_update(request): return render(request, "update.html", context) -@login_required -@require_http_methods(["GET", "POST"]) -def notification_update(request): - gymnast_list = Gymnast.objects.filter(is_active=True) +# @login_required +# @require_http_methods(["GET", "POST"]) +# def notification_update(request): +# gymnast_list = Gymnast.objects.filter(is_active=True) - context = { - "gymnast_list": gymnast_list, - "functionality_list": FUNCTIONALITY_CHOICES, - } - return render(request, "notification_update.html", context) +# context = { +# "gymnast_list": gymnast_list, +# "functionality_list": FUNCTIONALITY_CHOICES, +# } +# return render(request, "notification_update.html", context) -@require_http_methods(["POST"]) -def notification_add(request): - """ - Ajoute une demande de notification - """ - gymnast_id = request.POST.get("gymnast_id", None) - notification_id = request.POST.get("notification_id", None) +# @require_http_methods(["POST"]) +# def notification_add(request): +# """ +# Ajoute une demande de notification +# """ +# gymnast_id = request.POST.get("gymnast_id", None) +# notification_id = request.POST.get("notification_id", None) - gymnast = get_object_or_404(Gymnast, pk=gymnast_id) - row, created = Notification.objects.get_or_create( - user=request.user, gymnast=gymnast, functionality=notification_id - ) +# gymnast = get_object_or_404(Gymnast, pk=gymnast_id) +# row, created = Notification.objects.get_or_create( +# user=request.user, gymnast=gymnast, functionality=notification_id +# ) - if created: - return HttpResponse(200, (row, created)) # devrait être un 201 - else: - return HttpResponse(400, (row, created)) +# if created: +# return HttpResponse(200, (row, created)) # devrait être un 201 +# else: +# return HttpResponse(400, (row, created)) -@require_http_methods(["POST"]) -def notification_remove(request): - """ - Supprime une demande de notification - """ - gymnast_id = request.POST.get("gymnast_id", None) - notification_id = request.POST.get("notification_id", None) +# @require_http_methods(["POST"]) +# def notification_remove(request): +# """ +# Supprime une demande de notification +# """ +# gymnast_id = request.POST.get("gymnast_id", None) +# notification_id = request.POST.get("notification_id", None) - try: - Notification.objects.get( - user=request.user, gymnast=gymnast_id, functionality=notification_id - ).delete() - except Exception: - return HttpResponse(409) +# try: +# Notification.objects.get( +# user=request.user, gymnast=gymnast_id, functionality=notification_id +# ).delete() +# except Exception: +# return HttpResponse(409) - return HttpResponse(200) +# return HttpResponse(200) diff --git a/jarvis/tools/templatetags/get_item.py b/jarvis/tools/templatetags/get_item.py new file mode 100644 index 0000000..d26a920 --- /dev/null +++ b/jarvis/tools/templatetags/get_item.py @@ -0,0 +1,8 @@ +from django import template + +register = template.Library() + + +@register.filter +def get_item(dictionary, key): + return dictionary.get(key)