mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-28 23:43:22 +00:00
feat: Preparation des modèles Settings pour l'enregistrement SMTP [#17]
This commit is contained in:
@ -8,14 +8,8 @@ WORKDIR /Back-End
|
||||
# Allows docker to cache installed dependencies between builds
|
||||
COPY requirements.txt requirements.txt
|
||||
RUN pip install -r requirements.txt
|
||||
RUN pip install pymupdf
|
||||
|
||||
# Mounts the application code to the image
|
||||
COPY . .
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
ENV DJANGO_SETTINGS_MODULE N3wtSchool.settings
|
||||
ENV DJANGO_SUPERUSER_PASSWORD=admin
|
||||
ENV DJANGO_SUPERUSER_USERNAME=admin
|
||||
ENV DJANGO_SUPERUSER_EMAIL=admin@n3wtschool.com
|
||||
|
||||
@ -45,6 +45,7 @@ INSTALLED_APPS = [
|
||||
'School.apps.SchoolConfig',
|
||||
'Planning.apps.PlanningConfig',
|
||||
'Establishment.apps.EstablishmentConfig',
|
||||
'Settings.apps.SettingsConfig',
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
|
||||
@ -47,6 +47,7 @@ urlpatterns = [
|
||||
path("DocuSeal/", include(("DocuSeal.urls", 'DocuSeal'), namespace='DocuSeal')),
|
||||
path("Planning/", include(("Planning.urls", 'Planning'), namespace='Planning')),
|
||||
path("Establishment/", include(("Establishment.urls", 'Establishment'), namespace='Establishment')),
|
||||
path("Settings/", include(("Settings.urls", 'Settings'), namespace='Settings')),
|
||||
# Documentation Api
|
||||
re_path(r'^swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'),
|
||||
path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
|
||||
|
||||
@ -14,7 +14,7 @@ class RecursionType(models.IntegerChoices):
|
||||
RECURSION_CUSTOM = 4, _('Personnalisé')
|
||||
|
||||
class Planning(models.Model):
|
||||
establishment = models.ForeignKey(Establishment, on_delete=models.PROTECT)
|
||||
establishment = models.ForeignKey(Establishment, on_delete=models.CASCADE)
|
||||
school_class = models.ForeignKey(
|
||||
SchoolClass,
|
||||
on_delete=models.CASCADE,
|
||||
|
||||
1
Back-End/Settings/__init__.py
Normal file
1
Back-End/Settings/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
default_app_config = 'Settings.apps.SettingsConfig'
|
||||
3
Back-End/Settings/admin.py
Normal file
3
Back-End/Settings/admin.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
5
Back-End/Settings/apps.py
Normal file
5
Back-End/Settings/apps.py
Normal file
@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
class SettingsConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'Settings'
|
||||
17
Back-End/Settings/models.py
Normal file
17
Back-End/Settings/models.py
Normal file
@ -0,0 +1,17 @@
|
||||
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 Establishment.models import Establishment
|
||||
|
||||
class SMTPSettings(models.Model):
|
||||
establishment = models.ForeignKey(Establishment, on_delete=models.CASCADE)
|
||||
smtp_server = models.CharField(max_length=255)
|
||||
smtp_port = models.PositiveIntegerField()
|
||||
smtp_user = models.CharField(max_length=255)
|
||||
smtp_password = models.CharField(max_length=255)
|
||||
use_tls = models.BooleanField(default=True)
|
||||
use_ssl = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
return f"SMTP Settings ({self.smtp_server}:{self.smtp_port})"
|
||||
7
Back-End/Settings/serializers.py
Normal file
7
Back-End/Settings/serializers.py
Normal file
@ -0,0 +1,7 @@
|
||||
from rest_framework import serializers
|
||||
from .models import SMTPSettings
|
||||
|
||||
class SMTPSettingsSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = SMTPSettings
|
||||
fields = '__all__'
|
||||
6
Back-End/Settings/urls.py
Normal file
6
Back-End/Settings/urls.py
Normal file
@ -0,0 +1,6 @@
|
||||
from django.urls import path
|
||||
from .views import SMTPSettingsView
|
||||
|
||||
urlpatterns = [
|
||||
path('smtp-settings/', SMTPSettingsView.as_view(), name='smtp_settings'),
|
||||
]
|
||||
55
Back-End/Settings/views.py
Normal file
55
Back-End/Settings/views.py
Normal file
@ -0,0 +1,55 @@
|
||||
from drf_yasg.utils import swagger_auto_schema
|
||||
from drf_yasg import openapi
|
||||
from .models import SMTPSettings
|
||||
from .serializers import SMTPSettingsSerializer
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import status
|
||||
|
||||
class SMTPSettingsView(APIView):
|
||||
"""
|
||||
API pour gérer les paramètres SMTP.
|
||||
"""
|
||||
|
||||
@swagger_auto_schema(
|
||||
operation_description="Récupérer les paramètres SMTP",
|
||||
responses={
|
||||
200: SMTPSettingsSerializer(),
|
||||
404: openapi.Response(description="Aucun paramètre SMTP trouvé."),
|
||||
500: openapi.Response(description="Erreur interne du serveur."),
|
||||
},
|
||||
)
|
||||
def get(self, request):
|
||||
try:
|
||||
smtp_settings = SMTPSettings.objects.first()
|
||||
if not smtp_settings:
|
||||
return Response({'error': 'Aucun paramètre SMTP trouvé.'}, status=status.HTTP_404_NOT_FOUND)
|
||||
serializer = SMTPSettingsSerializer(smtp_settings)
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
except Exception as e:
|
||||
return Response({'error': str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||||
|
||||
@swagger_auto_schema(
|
||||
operation_description="Créer ou mettre à jour les paramètres SMTP",
|
||||
request_body=SMTPSettingsSerializer,
|
||||
responses={
|
||||
200: SMTPSettingsSerializer(),
|
||||
400: openapi.Response(description="Données invalides."),
|
||||
500: openapi.Response(description="Erreur interne du serveur."),
|
||||
},
|
||||
)
|
||||
def post(self, request):
|
||||
data = request.data
|
||||
try:
|
||||
smtp_settings = SMTPSettings.objects.first()
|
||||
if smtp_settings:
|
||||
serializer = SMTPSettingsSerializer(smtp_settings, data=data)
|
||||
else:
|
||||
serializer = SMTPSettingsSerializer(data=data)
|
||||
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||
except Exception as e:
|
||||
return Response({'error': str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||||
Binary file not shown.
@ -16,6 +16,7 @@ commands = [
|
||||
["python", "manage.py", "collectstatic", "--noinput"],
|
||||
["python", "manage.py", "flush", "--noinput"],
|
||||
["python", "manage.py", "makemigrations", "Establishment", "--noinput"],
|
||||
["python", "manage.py", "makemigrations", "Settings", "--noinput"],
|
||||
["python", "manage.py", "makemigrations", "Subscriptions", "--noinput"],
|
||||
["python", "manage.py", "makemigrations", "Planning", "--noinput"],
|
||||
["python", "manage.py", "makemigrations", "GestionNotification", "--noinput"],
|
||||
|
||||
Reference in New Issue
Block a user