diff --git a/settings/templates/settings/settings.html b/settings/templates/settings/settings.html index 9f99ea0..fe9cd93 100644 --- a/settings/templates/settings/settings.html +++ b/settings/templates/settings/settings.html @@ -65,6 +65,33 @@ {% endfor %} +

Pages statiques

+ + + Créer une nouvelle page statique + +
+
+ + + + + +{% for p in static_pages %} + + + + +{% endfor %} +
Nom
{{p.name}} + + Éditer + + + + Supprimer + +

Écoles

diff --git a/settings/templates/settings/static_page.html b/settings/templates/settings/static_page.html new file mode 100644 index 0000000..f81fe10 --- /dev/null +++ b/settings/templates/settings/static_page.html @@ -0,0 +1,5 @@ +{% extends "base.html" %} +{% block content %} +

{{object.name}}

+{{object.text|safe}} +{% endblock %} diff --git a/settings/templatetags/load_settings.py b/settings/templatetags/load_settings.py index e45c9b1..a1f1f6a 100644 --- a/settings/templatetags/load_settings.py +++ b/settings/templatetags/load_settings.py @@ -1,5 +1,5 @@ from django import template -from settings.models import SiteSettings +from settings.models import SiteSettings, StaticPage register = template.Library() @@ -9,7 +9,18 @@ def load_site_settings(parser, token): return LoadSiteSettingsNode() +@register.tag('load_static_pages') +def load_static_pages(parser, token): + return LoadStaticPagesNode() + + class LoadSiteSettingsNode(template.Node): def render(self, context): context['site_settings'] = SiteSettings.get_settings() return '' + + +class LoadStaticPagesNode(template.Node): + def render(self, context): + context['static_pages'] = StaticPage.objects.all() + return '' diff --git a/settings/urls.py b/settings/urls.py index 9293762..c21ba79 100644 --- a/settings/urls.py +++ b/settings/urls.py @@ -1,5 +1,5 @@ from django.urls import path -from .views import SettingsView, EditSiteSettingsView, degrade_user, promote_user +from .views import SettingsView, EditSiteSettingsView, degrade_user, promote_user, CreateStaticPageView, StaticPageView, DeleteStaticPageView, EditStaticPageView app_name = 'settings' urlpatterns = [ @@ -22,6 +22,25 @@ urlpatterns = [ 'promote_user', promote_user, name='promote-user', + ), + path( + 'static_page/new', + CreateStaticPageView.as_view(), + name='staticpage-new' + ), + path( + 'static_page/', + StaticPageView.as_view(), + name='staticpage' + ), + path( + 'static_page//delete', + DeleteStaticPageView.as_view(), + name='staticpage-delete' + ), + path( + 'static_page//edit', + EditStaticPageView.as_view(), + name='staticpage-edit' ) - ] diff --git a/settings/views.py b/settings/views.py index ab09c6a..7ce5dab 100644 --- a/settings/views.py +++ b/settings/views.py @@ -1,4 +1,4 @@ -from django.views.generic import TemplateView, UpdateView +from django.views.generic import TemplateView, UpdateView, CreateView, DetailView, DeleteView from django.urls import reverse_lazy, reverse from django.contrib.auth.mixins import PermissionRequiredMixin, LoginRequiredMixin from django.contrib.admin.views.decorators import staff_member_required @@ -8,7 +8,7 @@ from django.contrib import messages from content.models import Category from users.models import School -from .models import SiteSettings +from .models import SiteSettings, StaticPage from .forms import SelectUserForm @@ -23,8 +23,10 @@ class SettingsView(LoginRequiredMixin, PermissionRequiredMixin, TemplateView): context['schools'] = School.objects.all() context['settings'] = True context['administrators'] = User.objects.filter(is_staff=True) + context['static_pages'] = StaticPage.objects.all() return context + class EditSiteSettingsView(LoginRequiredMixin, PermissionRequiredMixin, UpdateView): template_name = "edit.html" model = SiteSettings @@ -42,6 +44,66 @@ class EditSiteSettingsView(LoginRequiredMixin, PermissionRequiredMixin, UpdateVi return context +class CreateStaticPageView(LoginRequiredMixin, CreateView): + template_name = "edit.html" + model = StaticPage + fields = '__all__' + success_url = reverse_lazy('settings:index') + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context["title"] = "Création de page statique" + context["validate"] = "Créer" + return context + + @classmethod + def as_view(self, *args, **kwargs): + view = super().as_view(*args, **kwargs) + return staff_member_required(view) + + +class StaticPageView(DetailView): + template_name = "settings/static_page.html" + model = StaticPage + fields = '__all__' + @classmethod + def as_view(self, *args, **kwargs): + view = super().as_view(*args, **kwargs) + return staff_member_required(view) + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['page'] = self.object + return context + + +class DeleteStaticPageView(DeleteView): + template_name = "confirm_delete.html" + model = StaticPage + success_url = reverse_lazy('settings:index') + @classmethod + def as_view(self, *args, **kwargs): + view = super().as_view(*args, **kwargs) + return staff_member_required(view) + + +class EditStaticPageView(UpdateView): + template_name = "edit.html" + model = StaticPage + success_url = reverse_lazy('settings:index') + fields = '__all__' + @classmethod + def as_view(self, *args, **kwargs): + view = super().as_view(*args, **kwargs) + return staff_member_required(view) + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context["title"] = "Édition de page statique" + context["validate"] = "Éditer" + return context + + @staff_member_required def degrade_user(request, pk): user = get_object_or_404(User, pk=pk) diff --git a/templates/nav_bar.html b/templates/nav_bar.html index f48ddd9..215eae3 100644 --- a/templates/nav_bar.html +++ b/templates/nav_bar.html @@ -2,6 +2,7 @@ {% load load_settings %} {% load_categories %} {% load_site_settings %} +{% load_static_pages %}