Ajout connexion/déconnexion à l'espace membres
This commit is contained in:
parent
3d1b8a9bee
commit
6c3a1e6ddc
31
beesgospel/forms.py
Normal file
31
beesgospel/forms.py
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
from dajngo import forms
|
||||||
|
from django.contrib.auth import forms as auth_forms
|
||||||
|
|
||||||
|
|
||||||
|
class BootstrapMixin:
|
||||||
|
required_css_class = "required"
|
||||||
|
|
||||||
|
widget_classes = {
|
||||||
|
"checkbox": "form-check-input",
|
||||||
|
"select": "form-select",
|
||||||
|
}
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
for field in self.fields.values():
|
||||||
|
if getattr(field.widget, "_bs_enabled", False):
|
||||||
|
continue
|
||||||
|
widgets = getattr(field.widget, "widgets", [field.widget])
|
||||||
|
for widget in widgets:
|
||||||
|
input_type = getattr(widget, "input_type", "")
|
||||||
|
class_name = self.widget_classes.get(input_type, "form-control")
|
||||||
|
if "class" in widget.attrs:
|
||||||
|
widget.attrs["class"] += " " + class_name
|
||||||
|
else:
|
||||||
|
widget.attrs.update({"class": class_name})
|
||||||
|
|
||||||
|
|
||||||
|
class LoginForm(BootstrapMixin, auth_forms.AuthenticationForm):
|
||||||
|
username = forms.EmailField(
|
||||||
|
widget=forms.EmailInput(attrs={"autofocus": True}),
|
||||||
|
)
|
13
beesgospel/views.py
Normal file
13
beesgospel/views.py
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
|
from django.views.generic import ListView, TemplateView
|
||||||
|
|
||||||
|
from .models import Membre
|
||||||
|
|
||||||
|
|
||||||
|
class EspaceMembresView(LoginRequiredMixin, TemplateView):
|
||||||
|
template_name = "membres/index.html"
|
||||||
|
|
||||||
|
|
||||||
|
class ListeMembresView(LoginRequiredMixin, ListView):
|
||||||
|
model = Membre
|
||||||
|
template_name = "membres/liste.html"
|
|
@ -4,6 +4,8 @@ Django settings for beesgospel project.
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
from django.urls import reverse_lazy
|
||||||
|
|
||||||
# Build paths inside the project like this: BASE_DIR / "subdir".
|
# Build paths inside the project like this: BASE_DIR / "subdir".
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
|
|
||||||
|
@ -109,6 +111,8 @@ USE_TZ = True
|
||||||
STATIC_URL = "static/"
|
STATIC_URL = "static/"
|
||||||
STATIC_ROOT = BASE_DIR / "static"
|
STATIC_ROOT = BASE_DIR / "static"
|
||||||
|
|
||||||
|
LOGOUT_REDIRECT_URL = reverse_lazy("presentation")
|
||||||
|
|
||||||
# Default primary key field type
|
# Default primary key field type
|
||||||
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field
|
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path
|
from django.urls import include, path
|
||||||
from django.views.generic import TemplateView
|
from django.views.generic import TemplateView
|
||||||
|
|
||||||
|
from beesgospel import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("admin/", admin.site.urls),
|
path("admin/", admin.site.urls),
|
||||||
|
path("accounts/", include("django.contrib.auth.urls")),
|
||||||
path("", TemplateView.as_view(template_name="index.html"), name="home"),
|
path("", TemplateView.as_view(template_name="index.html"), name="home"),
|
||||||
path("v2", TemplateView.as_view(template_name="index2.html"), name="home"),
|
path("v2", TemplateView.as_view(template_name="index2.html"), name="home"),
|
||||||
path("presentation/", TemplateView.as_view(template_name="presentation.html"), name="presentation"),
|
path("presentation/", TemplateView.as_view(template_name="presentation.html"), name="presentation"),
|
||||||
path("contact/", TemplateView.as_view(template_name="contact.html"), name="contact"),
|
path("contact/", TemplateView.as_view(template_name="contact.html"), name="contact"),
|
||||||
|
path("membres/", views.EspaceMembresView.as_view(), name="membres"),
|
||||||
|
path("membres/liste/", views.ListeMembresView.as_view(), name="liste-membres"),
|
||||||
]
|
]
|
||||||
|
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
django==5.2.*
|
||||||
|
pillow==11.3.*
|
|
@ -30,7 +30,7 @@
|
||||||
<li class="nav-sep">•</li>
|
<li class="nav-sep">•</li>
|
||||||
<li class="nav-item"><a class="nav-link" href="#">Médias</a></li>
|
<li class="nav-item"><a class="nav-link" href="#">Médias</a></li>
|
||||||
<li class="nav-sep">•</li>
|
<li class="nav-sep">•</li>
|
||||||
<li class="nav-item"><a class="nav-link" href="#">Espace membres</a></li>
|
<li class="nav-item"><a class="nav-link{% if request.path == "/membres/" %} active{% endif %}" href="{% url 'membres' %}">Espace membres</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
11
templates/membres/index.html
Normal file
11
templates/membres/index.html
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="float-end">
|
||||||
|
<form action="{% url 'logout' %}" method="post">{% csrf_token %}<button class="btn btn-sm btn-light" type="submit">Déconnexion</button></form>
|
||||||
|
</div>
|
||||||
|
<h2>Espace membres</h2>
|
||||||
|
<div class="row">
|
||||||
|
<a href="{% url 'liste-membres' %}">Liste des membres</a>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
14
templates/membres/liste.html
Normal file
14
templates/membres/liste.html
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h2>Liste des membres</h2>
|
||||||
|
<table class="table table-responsive">
|
||||||
|
{% for membre in object_list %}
|
||||||
|
<tr><td>{{ membre.nom }} {{ membre.prenom }}</td>
|
||||||
|
<td>{{ membre.rue }}<br>{{ membre.npa }} {{ membre.localite }}</td>
|
||||||
|
<td>{{ membre.tel1 }}<br>{{ membre.tel2 }}</td>
|
||||||
|
<td>{{ membre.email }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
{% endblock %}
|
26
templates/registration/login.html
Normal file
26
templates/registration/login.html
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="wrapper container">
|
||||||
|
<div class="col-11 col-lg-5 mx-auto">
|
||||||
|
<form class="form-sign mb-3" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
<h1 class="fs-2 mb-4">Connexion</h1>
|
||||||
|
|
||||||
|
{{ form.non_field_errors }}
|
||||||
|
<div class="mb-4">
|
||||||
|
<label for="id_username" class="form-label w-100">Adresse électronique</label>
|
||||||
|
{{ form.username.errors }} {{ form.username }}
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="id_password" class="form-label w-100">Mot de passe</label>
|
||||||
|
{{ form.password.errors }} {{ form.password }}
|
||||||
|
</div>
|
||||||
|
<!--div class="mb-4">
|
||||||
|
<a href="{% url 'password_reset' %}" class="text-link">Mot de passe oublié</a>
|
||||||
|
</div-->
|
||||||
|
<button class="btn btn-cta btn-light" type="submit">Se connecter</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock content %}
|
Loading…
Reference in a new issue