From 2154e6f02252576d8652e66f26fa4ae635d0f8ee Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Thu, 17 Nov 2022 17:43:00 -0700 Subject: Rework UI to have vertical menus --- users/views/admin.py | 10 +++++++++- users/views/settings.py | 28 +++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 6 deletions(-) (limited to 'users') diff --git a/users/views/admin.py b/users/views/admin.py index 165572c..9476417 100644 --- a/users/views/admin.py +++ b/users/views/admin.py @@ -24,7 +24,6 @@ class AdminSettingsPage(SettingsPage): at the bottom of the page. Don't add this to a URL directly - subclass! """ - template_name = "admin/settings.html" options_class = Config.SystemOptions def load_config(self): @@ -47,6 +46,15 @@ class BasicPage(AdminSettingsPage): "title": "Highlight Color", "help_text": "Used for logo background and other highlights", }, + "post_length": { + "title": "Maximum Post Length", + "help_text": "The maximum number of characters allowed per post", + }, + } + + layout = { + "Branding": ["site_name", "highlight_color"], + "Posts": ["post_length"], } diff --git a/users/views/settings.py b/users/views/settings.py index c3c166b..88e4cd3 100644 --- a/users/views/settings.py +++ b/users/views/settings.py @@ -1,5 +1,5 @@ from functools import partial -from typing import ClassVar, Dict +from typing import ClassVar, Dict, List from django import forms from django.shortcuts import redirect @@ -27,6 +27,7 @@ class SettingsPage(FormView): template_name = "settings/settings.html" section: ClassVar[str] options: Dict[str, Dict[str, str]] + layout: Dict[str, List[str]] def get_form_class(self): # Create the fields dict from the config object @@ -42,6 +43,8 @@ class SettingsPage(FormView): ) elif config_field.type_ is str: form_field = forms.CharField + elif config_field.type_ is int: + form_field = forms.IntegerField else: raise ValueError(f"Cannot render settings type {config_field.type_}") fields[key] = form_field( @@ -68,6 +71,10 @@ class SettingsPage(FormView): def get_context_data(self): context = super().get_context_data() context["section"] = self.section + # Gather fields into fieldsets + context["fieldsets"] = {} + for title, fields in self.layout.items(): + context["fieldsets"][title] = [context["form"][field] for field in fields] return context def form_valid(self, form): @@ -87,10 +94,12 @@ class InterfacePage(SettingsPage): options = { "toot_mode": { "title": "I Will Toot As I Please", - "help_text": "If enabled, changes all 'Post' buttons to 'Toot!'", + "help_text": "Changes all 'Post' buttons to 'Toot!'", } } + layout = {"Posting": ["toot_mode"]} + @method_decorator(identity_required, name="dispatch") class ProfilePage(FormView): @@ -102,9 +111,18 @@ class ProfilePage(FormView): class form_class(forms.Form): name = forms.CharField(max_length=500) - summary = forms.CharField(widget=forms.Textarea, required=False) - icon = forms.ImageField(required=False) - image = forms.ImageField(required=False) + summary = forms.CharField( + widget=forms.Textarea, + required=False, + help_text="Describe you and your interests", + label="Bio", + ) + icon = forms.ImageField( + required=False, help_text="Shown next to all your posts and activities" + ) + image = forms.ImageField( + required=False, help_text="Shown at the top of your profile" + ) def get_initial(self): return { -- cgit v1.2.3