2021-01-29 23:38:42 +00:00
|
|
|
''' manage site settings '''
|
|
|
|
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
|
|
|
|
@method_decorator(login_required, name='dispatch')
|
|
|
|
@method_decorator(
|
|
|
|
permission_required(
|
|
|
|
'bookwyrm.edit_instance_settings', raise_exception=True),
|
|
|
|
name='dispatch')
|
|
|
|
class Site(View):
|
|
|
|
''' manage things like the instance name '''
|
|
|
|
def get(self, request):
|
|
|
|
''' edit form '''
|
|
|
|
site = models.SiteSettings.objects.get()
|
2021-02-28 18:00:36 +00:00
|
|
|
data = {'site_form': forms.SiteForm(instance=site)}
|
2021-01-29 23:38:42 +00:00
|
|
|
return TemplateResponse(request, 'settings/site.html', data)
|
|
|
|
|
|
|
|
def post(self, request):
|
|
|
|
''' edit the site settings '''
|
2021-01-29 23:50:46 +00:00
|
|
|
site = models.SiteSettings.objects.get()
|
|
|
|
form = forms.SiteForm(request.POST, instance=site)
|
|
|
|
if not form.is_valid():
|
2021-02-28 18:00:36 +00:00
|
|
|
data = {'site_form': form}
|
2021-01-29 23:50:46 +00:00
|
|
|
return TemplateResponse(request, 'settings/site.html', data)
|
|
|
|
form.save()
|
2021-01-29 23:38:42 +00:00
|
|
|
|
2021-01-29 23:50:46 +00:00
|
|
|
return redirect('settings-site')
|