mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-28 23:43:22 +00:00
chore: Initial Commit
feat: Gestion des inscriptions [#1] feat(frontend): Création des vues pour le paramétrage de l'école [#2] feat: Gestion du login [#6] fix: Correction lors de la migration des modèle [#8] feat: Révision du menu principal [#9] feat: Ajout d'un footer [#10] feat: Création des dockers compose pour les environnements de développement et de production [#12] doc(ci): Mise en place de Husky et d'un suivi de version automatique [#14]
This commit is contained in:
1
Back-End/GestionNotification/__init__.py
Normal file
1
Back-End/GestionNotification/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
default_app_config = 'GestionNotification.apps.GestionNotificationConfig'
|
||||
3
Back-End/GestionNotification/admin.py
Normal file
3
Back-End/GestionNotification/admin.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
9
Back-End/GestionNotification/apps.py
Normal file
9
Back-End/GestionNotification/apps.py
Normal file
@ -0,0 +1,9 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
class GestionNotificationConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'GestionNotification'
|
||||
|
||||
def ready(self):
|
||||
import GestionNotification.signals
|
||||
|
||||
28
Back-End/GestionNotification/models.py
Normal file
28
Back-End/GestionNotification/models.py
Normal file
@ -0,0 +1,28 @@
|
||||
from django.contrib.auth.models import AbstractUser
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.conf import settings
|
||||
from GestionLogin.models import Profil
|
||||
|
||||
class TypeNotif(models.IntegerChoices):
|
||||
NOTIF_NONE = 0, _('Aucune notification')
|
||||
NOTIF_MESSAGE = 1, _('Un message a été reçu')
|
||||
NOTIF_DI = 2, _('Le dossier d\'inscription a été mis à jour')
|
||||
|
||||
class Notification(models.Model):
|
||||
user = models.ForeignKey(Profil, on_delete=models.PROTECT)
|
||||
message = models.CharField(max_length=255)
|
||||
is_read = models.BooleanField(default=False)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
typeNotification = models.IntegerField(choices=TypeNotif, default=0)
|
||||
|
||||
@property
|
||||
def typeNotification_label(self):
|
||||
return self.get_typeNotification_display()
|
||||
|
||||
def get_typeNotification_display(self):
|
||||
return TypeNotif(self.typeNotification).label
|
||||
|
||||
def __str__(self):
|
||||
return f'Notification for {self.user.username}'
|
||||
|
||||
23
Back-End/GestionNotification/signals.py
Normal file
23
Back-End/GestionNotification/signals.py
Normal file
@ -0,0 +1,23 @@
|
||||
from django.db.models.signals import post_save
|
||||
from django.dispatch import receiver
|
||||
from .models import Notification, TypeNotif
|
||||
from GestionMessagerie.models import Messagerie
|
||||
from GestionInscriptions.models import FicheInscription
|
||||
|
||||
@receiver(post_save, sender=Messagerie)
|
||||
def notification_MESSAGE(sender, instance, created, **kwargs):
|
||||
if created:
|
||||
Notification.objects.create(
|
||||
user=instance.destinataire,
|
||||
message=(TypeNotif.NOTIF_MESSAGE).label,
|
||||
typeNotification=TypeNotif.NOTIF_MESSAGE
|
||||
)
|
||||
|
||||
@receiver(post_save, sender=FicheInscription)
|
||||
def notification_DI(sender, instance, created, **kwargs):
|
||||
for responsable in instance.eleve.responsables.all():
|
||||
Notification.objects.create(
|
||||
user=responsable.profilAssocie,
|
||||
message=(TypeNotif.NOTIF_DI).label,
|
||||
typeNotification=TypeNotif.NOTIF_DI
|
||||
)
|
||||
7
Back-End/GestionNotification/urls.py
Normal file
7
Back-End/GestionNotification/urls.py
Normal file
@ -0,0 +1,7 @@
|
||||
from django.urls import path, re_path
|
||||
|
||||
from GestionNotification.views import NotificationView
|
||||
|
||||
urlpatterns = [
|
||||
re_path(r'^notification$', NotificationView.as_view(), name="notification"),
|
||||
]
|
||||
15
Back-End/GestionNotification/views.py
Normal file
15
Back-End/GestionNotification/views.py
Normal file
@ -0,0 +1,15 @@
|
||||
from django.http.response import JsonResponse
|
||||
from rest_framework.views import APIView
|
||||
|
||||
from .models import *
|
||||
|
||||
from GestionInscriptions.serializers import NotificationSerializer
|
||||
|
||||
from N3wtSchool import bdd
|
||||
|
||||
class NotificationView(APIView):
|
||||
def get(self, request):
|
||||
notifsList=bdd.getAllObjects(Notification)
|
||||
notifs_serializer=NotificationSerializer(notifsList, many=True)
|
||||
|
||||
return JsonResponse(notifs_serializer.data, safe=False)
|
||||
Reference in New Issue
Block a user