summaryrefslogtreecommitdiffstats
path: root/users/views
diff options
context:
space:
mode:
authorAndrew Godwin2022-11-17 19:21:00 -0700
committerAndrew Godwin2022-11-17 17:33:09 -0700
commit291d7e404e12e1d017403242f8ed199046f0904c (patch)
tree89a60ff7f321537b6a58835aaa726f7e22ed09ba /users/views
parent0851fbd1ec09b142608667bf90ee806e59cafb28 (diff)
downloadtakahe-291d7e404e12e1d017403242f8ed199046f0904c.tar.gz
takahe-291d7e404e12e1d017403242f8ed199046f0904c.tar.bz2
takahe-291d7e404e12e1d017403242f8ed199046f0904c.zip
Logged out experience, config, and profiles
Diffstat (limited to 'users/views')
-rw-r--r--users/views/admin.py22
-rw-r--r--users/views/settings.py30
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)