35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
from django.views.generic import TemplateView, UpdateView
|
|
from django.urls import reverse_lazy
|
|
from content.models import Category
|
|
from users.models import SchoolProfile
|
|
from .models import ContentSettings, SiteSettings
|
|
|
|
|
|
class SettingsView(TemplateView):
|
|
template_name = "settings/settings.html"
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super().get_context_data(**kwargs)
|
|
context['categories'] = Category.objects.all()
|
|
context['site_settings'], _ = SiteSettings.objects.get_or_create()
|
|
context['content_settings'], _ = ContentSettings.objects.get_or_create()
|
|
context['schools'] = SchoolProfile.objects.all()
|
|
context['settings'] = True
|
|
return context
|
|
|
|
class EditSiteSettingsView(UpdateView):
|
|
template_name = "edit.html"
|
|
model = SiteSettings
|
|
fields = '__all__'
|
|
success_url = reverse_lazy('settings:index')
|
|
|
|
def get_object(self, queryset=None):
|
|
obj,_ = self.model.objects.get_or_create()
|
|
return obj
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super(UpdateView, self).get_context_data(**kwargs)
|
|
context['title'] = "Édition des " + self.object.PRETTY_NAME
|
|
return context
|
|
|
|
|