moviewyrm/bookwyrm/views/site.py

36 lines
1.2 KiB
Python
Raw Normal View History

2021-03-08 16:49:10 +00:00
""" manage site settings """
2021-01-29 23:38:42 +00:00
from django.contrib.auth.decorators import login_required, permission_required
from django.shortcuts import redirect
from django.template.response import TemplateResponse
from django.utils.decorators import method_decorator
from django.views import View
from bookwyrm import forms, models
# pylint: disable= no-self-use
2021-03-08 16:49:10 +00:00
@method_decorator(login_required, name="dispatch")
2021-01-29 23:38:42 +00:00
@method_decorator(
2021-03-08 16:49:10 +00:00
permission_required("bookwyrm.edit_instance_settings", raise_exception=True),
name="dispatch",
)
2021-01-29 23:38:42 +00:00
class Site(View):
2021-03-08 16:49:10 +00:00
""" manage things like the instance name """
2021-01-29 23:38:42 +00:00
def get(self, request):
2021-03-08 16:49:10 +00:00
""" edit form """
2021-01-29 23:38:42 +00:00
site = models.SiteSettings.objects.get()
2021-03-08 16:49:10 +00:00
data = {"site_form": forms.SiteForm(instance=site)}
return TemplateResponse(request, "settings/site.html", data)
2021-01-29 23:38:42 +00:00
def post(self, request):
2021-03-08 16:49:10 +00:00
""" edit the site settings """
2021-01-29 23:50:46 +00:00
site = models.SiteSettings.objects.get()
form = forms.SiteForm(request.POST, request.FILES, instance=site)
2021-01-29 23:50:46 +00:00
if not form.is_valid():
2021-03-08 16:49:10 +00:00
data = {"site_form": form}
return TemplateResponse(request, "settings/site.html", data)
2021-01-29 23:50:46 +00:00
form.save()
2021-01-29 23:38:42 +00:00
2021-03-08 16:49:10 +00:00
return redirect("settings-site")