From a72de2bb102f5afd08da9d78ae96a004dd3736b6 Mon Sep 17 00:00:00 2001 From: blankie Date: Sun, 14 Jun 2026 08:46:21 +0000 Subject: [PATCH] auto-save: settings save on change via /style/field, noscript fallback button --- handlers/__init__.py | 4 +++- handlers/customize.py | 50 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/handlers/__init__.py b/handlers/__init__.py index 0b4365e..e7eda3e 100644 --- a/handlers/__init__.py +++ b/handlers/__init__.py @@ -32,7 +32,7 @@ from .subscriptions import ( handle_subscription_delete, handle_subscription_syncall, _sync_threads, ) -from .customize import handle_style_form, handle_style_submit, handle_style_template_submit, handle_about +from .customize import handle_style_form, handle_style_submit, handle_style_template_submit, handle_field_save, handle_about from .tags import handle_tags, handle_tag_browse from .data import ( handle_export, handle_import_form, handle_import_submit, @@ -125,6 +125,8 @@ def _dispatch_inner(data): return handle_style_submit(body, gateway_host=gateway_host, scheme=scheme) elif path == "/style/template": return handle_style_template_submit(body, gateway_host=gateway_host, scheme=scheme) + elif path == "/style/field": + return handle_field_save(body) elif path == "/style/reset": set_setting("custom_template", "") return handle_style_form("Template reset to default.", gateway_host=gateway_host, scheme=scheme) diff --git a/handlers/customize.py b/handlers/customize.py index 02ad2d2..6808046 100644 --- a/handlers/customize.py +++ b/handlers/customize.py @@ -1,7 +1,7 @@ from db import get_db, return_db, get_setting, set_setting, get_site_name import templates as templates_mod from templates import esc, DEFAULT_TEMPLATE -from ._helpers import _respond, _csrf_field, _get_bookmark_token +from ._helpers import _respond, _json_response, _csrf_field, _get_bookmark_token from .subscriptions import _count_shared_pages @@ -54,7 +54,7 @@ def handle_style_form(msg="", gateway_host="", scheme="http"): return _respond( f"

customize

" f"

name your search engine

" - f'
' + f'' f'{_csrf_field()}' f'

' f"

sharing

" @@ -127,8 +127,26 @@ def handle_style_form(msg="", gateway_host="", scheme="http"): f'manage semantic index

' f"" f"{forum_section}" - f'' + f'

' + f'' f"
" + '' f"

custom html

" f"

Edit the full page template. Use {esc('{{content}}')} " f"where page content should appear.

" @@ -223,6 +241,32 @@ def handle_style_template_submit(body, gateway_host="", scheme="http"): return handle_style_form("Template saved.", gateway_host=gateway_host, scheme=scheme) +def handle_field_save(body): + key = body.get("key", [""])[0].strip() + value = body.get("value", [""])[0].strip() + if not key: + return _json_response({"status": "error", "message": "No key provided."}, 400) + if key == "forum_enabled": + from handlers import forum_plugin + if value == "1" and forum_plugin is None: + return _json_response({"status": "error", "message": "Forum plugin not installed."}, 400) + if value == "1": + forum_plugin.enable() + try: + forum_plugin.fdb.set_setting("forum_enabled", "1") + except Exception: + pass + else: + forum_plugin.disable() + try: + forum_plugin.fdb.set_setting("forum_enabled", "0") + except Exception: + pass + templates_mod.FORUM_ENABLED = (value == "1") + set_setting(key, value) + return _json_response({"status": "ok", "message": ""}) + + def handle_about(): name = get_site_name() dest_hash = get_setting("dest_hash")