From ed67cdb2d87251df4ab415d834f2f05f2a3d1984 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 6 Aug 2024 18:52:54 -0500 Subject: [PATCH] feat: add basic configure view for appinfo --- src/wuttaweb/app.py | 11 +- src/wuttaweb/forms/base.py | 1 + src/wuttaweb/helpers.py | 12 +- src/wuttaweb/templates/appinfo/configure.mako | 21 + src/wuttaweb/templates/base.mako | 29 +- src/wuttaweb/templates/configure.mako | 181 +++++++++ .../templates/forms/vue_template.mako | 1 + src/wuttaweb/templates/master/configure.mako | 9 + src/wuttaweb/util.py | 43 ++ src/wuttaweb/views/master.py | 367 +++++++++++++++++- src/wuttaweb/views/settings.py | 17 +- tests/test_app.py | 11 + tests/test_util.py | 43 ++ tests/views/test_master.py | 138 +++++-- tests/views/test_settings.py | 5 + 15 files changed, 847 insertions(+), 42 deletions(-) create mode 100644 src/wuttaweb/templates/appinfo/configure.mako create mode 100644 src/wuttaweb/templates/configure.mako create mode 100644 src/wuttaweb/templates/master/configure.mako diff --git a/src/wuttaweb/app.py b/src/wuttaweb/app.py index 6aadc0c..8b4a610 100644 --- a/src/wuttaweb/app.py +++ b/src/wuttaweb/app.py @@ -110,7 +110,11 @@ def make_pyramid_config(settings): The config is initialized with certain features deemed useful for all apps. + + :returns: Instance of + :class:`pyramid:pyramid.config.Configurator`. """ + settings.setdefault('mako.directories', ['wuttaweb:templates']) settings.setdefault('pyramid_deform.template_search_path', 'wuttaweb:templates/deform') @@ -119,6 +123,11 @@ def make_pyramid_config(settings): # configure user authorization / authentication pyramid_config.set_security_policy(WuttaSecurityPolicy()) + # require CSRF token for POST + pyramid_config.set_default_csrf_options(require_csrf=True, + token='_csrf', + header='X-CSRF-TOKEN') + pyramid_config.include('pyramid_beaker') pyramid_config.include('pyramid_deform') pyramid_config.include('pyramid_mako') @@ -143,8 +152,6 @@ def main(global_config, **settings): will need to define their own ``main()`` function, and use that instead. """ - settings.setdefault('mako.directories', ['wuttaweb:templates']) - wutta_config = make_wutta_config(settings) pyramid_config = make_pyramid_config(settings) diff --git a/src/wuttaweb/forms/base.py b/src/wuttaweb/forms/base.py index 0974a50..42abb31 100644 --- a/src/wuttaweb/forms/base.py +++ b/src/wuttaweb/forms/base.py @@ -323,6 +323,7 @@ class Form: """ context['form'] = self context.setdefault('form_attrs', {}) + context.setdefault('request', self.request) # auto disable button on submit if self.auto_disable_submit: diff --git a/src/wuttaweb/helpers.py b/src/wuttaweb/helpers.py index c80c62f..80b9d21 100644 --- a/src/wuttaweb/helpers.py +++ b/src/wuttaweb/helpers.py @@ -38,12 +38,20 @@ instance: This module contains the following references: -* :func:`~wuttaweb.util.get_liburl()` * all names from :mod:`webhelpers2:webhelpers2.html` * all names from :mod:`webhelpers2:webhelpers2.html.tags` +* :func:`~wuttaweb.util.get_liburl()` +* :func:`~wuttaweb.util.get_csrf_token()` +* :func:`~wuttaweb.util.render_csrf_token()` (as :func:`csrf_token()`) + +.. function:: csrf_token + + This is a shorthand reference to + :func:`wuttaweb.util.render_csrf_token()`. + """ from webhelpers2.html import * from webhelpers2.html.tags import * -from wuttaweb.util import get_liburl +from wuttaweb.util import get_liburl, get_csrf_token, render_csrf_token as csrf_token diff --git a/src/wuttaweb/templates/appinfo/configure.mako b/src/wuttaweb/templates/appinfo/configure.mako new file mode 100644 index 0000000..218d092 --- /dev/null +++ b/src/wuttaweb/templates/appinfo/configure.mako @@ -0,0 +1,21 @@ +## -*- coding: utf-8; -*- +<%inherit file="/configure.mako" /> + +<%def name="form_content()"> + +

Basics

+
+ + + + + + +
+ + + + +${parent.body()} diff --git a/src/wuttaweb/templates/base.mako b/src/wuttaweb/templates/base.mako index b04c980..6b5dfd9 100644 --- a/src/wuttaweb/templates/base.mako +++ b/src/wuttaweb/templates/base.mako @@ -209,16 +209,14 @@ -