Mon commit initial

This commit is contained in:
2025-12-19 09:43:33 +00:00
commit f11d1e62b4
336 changed files with 6247 additions and 0 deletions

View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,3 @@
from django.contrib import admin # noqa: F401
# Register your models here.

6
authentification/apps.py Normal file
View File

@@ -0,0 +1,6 @@
from django.apps import AppConfig
class AuthentificationConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "authentification"

View File

@@ -0,0 +1,33 @@
# Generated by Django 5.2.7 on 2025-11-11 07:12
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='Departement',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('nom_departement', models.TextField(verbose_name='Nom du département :')),
],
),
migrations.CreateModel(
name='Profile',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('chef_departement', models.BooleanField(verbose_name='Cet utilisateur est-il chef de ce département ?')),
('departement', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='authentification.departement')),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]

View File

View File

@@ -0,0 +1,39 @@
"""Modèles pour l'authentification et la gestion des profils utilisateurs."""
from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class Departement(models.Model):
"""Modèle représentant un département."""
nom_departement = models.TextField(verbose_name="Nom du département :")
def __str__(self):
"""Retourne une représentation en chaîne de caractères du dép."""
return self.nom_departement
class Profile(models.Model):
"""Modèle représentant le profil utilisateur.
Il étend le modèle User de Django avec des informations supplémentaires.
En y rajoutant notamment le département de l'utilisateur et s'il en est le
chef.
"""
user = models.OneToOneField(User, on_delete=models.CASCADE)
departement = models.ForeignKey(
Departement, on_delete=models.SET_NULL, null=True, blank=True
)
chef_departement = models.BooleanField(
verbose_name="Cet utilisateur est-il chef de ce département ?"
)
def __str__(self):
"""Retourne une représentation en chaîne de caractères du profil."""
return (
f"{self.user.first_name} {self.user.last_name} "
f"({self.departement.nom_departement})"
)

View File

@@ -0,0 +1,40 @@
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}">
<title>Connexion: SGL</title>
</head>
<body>
<div class="container-fluid">
<div class="row d-flex justify-content-center align-items-center vh-100 mt-4">
<div class="col-11 col-lg-5 border rounded p-2">
{% if messages %}
{% for message in messages %}
<div class="alert alert-danger">{{ message }}</div>
{% endfor %}
{% endif %}
<div style="height: 30px;">
<h4 class="text-center">Connexion</h4>
</div>
<form action="{% url 'authentification:login' %}" method="post">
{% csrf_token %}
<div class="form-group mt-2">
<label for="username">Nom d'utilisateur :</label>
<input type="text" class="form-control" name="username">
</div>
<div class="form-group mt-2">
<label for="password">Mot de passe :</label>
<input type="password" class="form-control" name="password">
</div>
<button type="submit" class="btn btn-primary mt-3 d-block m-auto">Connexion</button>
</form>
</div>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,29 @@
from django import template
from authentification.models import Profile
register = template.Library()
@register.filter
def has_group(user, group_name):
return user.groups.filter(name=group_name).exists()
# On recupère l'utilisateur et le produit
## Si l'utilisateur n'est pas le chef d'un département, afficher simplement ses demandes
## Si l'utilisateur est un chef de département
### Afficher la liste de ses demandes
### Verifier pour chaque demande que l'utilisateur appartient à son departement
#### Si oui, afficher le produit
#### Si non, ne pas afficher le produit
@register.filter
def affichage_demande(user, demande):
if user.profile.chef_departement:
chef_profile = Profile.objects.get(id=user.profile)
departement = chef_profile.departement
ids_profils_departement = Profile.objects.filter(departement=departement)["id"]
return demande.user_id in ids_profils_departement
return user.profile.id == demande.user_id

View File

@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

11
authentification/urls.py Normal file
View File

@@ -0,0 +1,11 @@
"""Routes pour l'authentification des utilisateurs."""
from django.urls import path
from . import views
app_name = "authentification"
urlpatterns = [
path("connexion", views.connexion, name="login"),
path("deconnexion", views.deconnexion, name="deconnexion"),
]

34
authentification/views.py Normal file
View File

@@ -0,0 +1,34 @@
"""Vues pour l'authentification des utilisateurs."""
from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login, logout
from django.contrib import messages
from SGL.views import index
def connexion(request):
"""Gérez la connexion des utilisateurs."""
authentification_echoue = False
if request.method == "POST":
username = request.POST["username"]
password = request.POST["password"]
user = authenticate(username=username, password=password)
if user is not None:
login(request, user)
return redirect(index)
messages.error(request, "Nom d'utilisateur ou mot de passe incorrect.")
return render(
request,
"authentification/login.html",
{"authentification_echoue": authentification_echoue},
)
def deconnexion(request):
"""Gérez la déconnexion des utilisateurs."""
logout(request)
return redirect("authentification:login")