moviewyrm/bookwyrm/views/admin/site.py

55 lines
2.1 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.template.response import TemplateResponse
from django.utils.decorators import method_decorator
from django.views import View
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()
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
2022-02-18 02:00:19 +00:00
data = {"site_form": forms.SiteForm(instance=site), "success": True}
return TemplateResponse(request, "settings/site.html", data)
@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")
data = emailing.email_data()
2021-09-27 17:21:46 +00:00
data["subject_path"] = f"email/{template}/subject.html"
data["html_content_path"] = f"email/{template}/html_content.html"
data["text_content_path"] = f"email/{template}/text_content.html"
data["reset_link"] = "https://example.com/link"
data["invite_link"] = "https://example.com/link"
2021-08-06 22:38:37 +00:00
data["confirmation_link"] = "https://example.com/link"
data["confirmation_code"] = "AKJHKDGKJSDFG"
2021-11-18 04:22:00 +00:00
data["reporter"] = "ConcernedUser"
data["reportee"] = "UserName"
data["report_link"] = "https://example.com/link"
return TemplateResponse(request, "email/preview.html", data)