site_tps/settings/views.py

29 lines
1,005 B
Python
Raw Normal View History

from django.views.generic import TemplateView, UpdateView
from django.urls import reverse_lazy
2018-01-30 20:39:44 +00:00
from content.models import Category
2018-01-31 10:53:37 +00:00
from users.models import SchoolProfile
2018-01-30 20:39:44 +00:00
from .models import ContentSettings, SiteSettings
2018-01-14 12:19:11 +00:00
2018-01-30 20:39:44 +00:00
class SettingsView(TemplateView):
template_name = "settings/settings.html"
2018-01-30 20:39:44 +00:00
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()
2018-01-31 10:53:37 +00:00
context['schools'] = SchoolProfile.objects.all()
context['settings'] = True
2018-01-30 20:39:44 +00:00
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