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
|
|
|
|
|
2021-03-21 18:43:14 +00:00
|
|
|
from bookwyrm import emailing, forms, models
|
2021-01-29 23:38:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
# 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-04-26 16:15:42 +00:00
|
|
|
"""manage things like the instance name"""
|
2021-03-08 16:49:10 +00:00
|
|
|
|
2021-01-29 23:38:42 +00:00
|
|
|
def get(self, request):
|
2021-04-26 16:15:42 +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-04-26 16:15:42 +00:00
|
|
|
"""edit the site settings"""
|
2021-01-29 23:50:46 +00:00
|
|
|
site = models.SiteSettings.objects.get()
|
2021-03-15 17:05:08 +00:00
|
|
|
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")
|
2021-03-21 18:43:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@permission_required("bookwyrm.edit_instance_settings", raise_exception=True)
|
|
|
|
def email_preview(request):
|
2021-04-26 16:15:42 +00:00
|
|
|
"""for development, renders and example email template"""
|
2021-03-21 19:07:58 +00:00
|
|
|
template = request.GET.get("email")
|
2021-03-21 18:43:14 +00:00
|
|
|
data = emailing.email_data()
|
|
|
|
data["subject_path"] = "email/{}/subject.html".format(template)
|
|
|
|
data["html_content_path"] = "email/{}/html_content.html".format(template)
|
|
|
|
data["text_content_path"] = "email/{}/text_content.html".format(template)
|
|
|
|
data["reset_link"] = "https://example.com/link"
|
|
|
|
data["invite_link"] = "https://example.com/link"
|
|
|
|
return TemplateResponse(request, "email/preview.html", data)
|