diff options
Diffstat (limited to 'users')
-rw-r--r-- | users/views/admin.py | 22 | ||||
-rw-r--r-- | users/views/settings.py | 30 |
2 files changed, 45 insertions, 7 deletions
diff --git a/users/views/admin.py b/users/views/admin.py index 9476417..d7f23e8 100644 --- a/users/views/admin.py +++ b/users/views/admin.py @@ -40,7 +40,6 @@ class BasicPage(AdminSettingsPage): options = { "site_name": { "title": "Site Name", - "help_text": "Shown in the top-left of the page, and titles", }, "highlight_color": { "title": "Highlight Color", @@ -50,10 +49,29 @@ class BasicPage(AdminSettingsPage): "title": "Maximum Post Length", "help_text": "The maximum number of characters allowed per post", }, + "site_about": { + "title": "About This Site", + "help_text": "Displayed on the homepage and the about page", + "display": "textarea", + }, + "site_icon": { + "title": "Site Icon", + "help_text": "Minimum size 64x64px. Should be square.", + }, + "site_banner": { + "title": "Site Banner", + "help_text": "Must be at least 650px wide. 3:1 ratio of width:height recommended.", + }, } layout = { - "Branding": ["site_name", "highlight_color"], + "Branding": [ + "site_name", + "site_about", + "site_icon", + "site_banner", + "highlight_color", + ], "Posts": ["post_length"], } diff --git a/users/views/settings.py b/users/views/settings.py index 88e4cd3..d823676 100644 --- a/users/views/settings.py +++ b/users/views/settings.py @@ -2,18 +2,19 @@ from functools import partial from typing import ClassVar, Dict, List from django import forms +from django.core.files import File from django.shortcuts import redirect from django.utils.decorators import method_decorator from django.views.generic import FormView, RedirectView from PIL import Image, ImageOps -from core.models import Config +from core.models.config import Config, UploadedImage from users.decorators import identity_required @method_decorator(identity_required, name="dispatch") class SettingsRoot(RedirectView): - url = "/settings/interface/" + pattern_name = "settings_profile" @method_decorator(identity_required, name="dispatch") @@ -41,8 +42,16 @@ class SettingsPage(FormView): choices=[(True, "Enabled"), (False, "Disabled")] ), ) + elif config_field.type_ is UploadedImage: + form_field = forms.ImageField elif config_field.type_ is str: - form_field = forms.CharField + if details.get("display") == "textarea": + form_field = partial( + forms.CharField, + widget=forms.Textarea, + ) + else: + form_field = forms.CharField elif config_field.type_ is int: form_field = forms.IntegerField else: @@ -80,6 +89,15 @@ class SettingsPage(FormView): def form_valid(self, form): # Save each key for field in form: + if field.field.__class__.__name__ == "ImageField": + # These can be cleared with an extra checkbox + if self.request.POST.get(f"{field.name}__clear"): + self.save_config(field.name, None) + continue + # We shove the preview values in initial_data, so only save file + # fields if they have a File object. + if not isinstance(form.cleaned_data[field.name], File): + continue self.save_config( field.name, form.cleaned_data[field.name], @@ -128,6 +146,8 @@ class ProfilePage(FormView): return { "name": self.request.identity.name, "summary": self.request.identity.summary, + "icon": self.request.identity.icon.url, + "image": self.request.identity.image.url, } def get_context_data(self): @@ -142,12 +162,12 @@ class ProfilePage(FormView): # Resize images icon = form.cleaned_data.get("icon") image = form.cleaned_data.get("image") - if icon: + if isinstance(icon, File): resized_image = ImageOps.fit(Image.open(icon), (400, 400)) icon.open() resized_image.save(icon) self.request.identity.icon = icon - if image: + if isinstance(image, File): resized_image = ImageOps.fit(Image.open(image), (1500, 500)) image.open() resized_image.save(image) |