diff --git a/pyproject.toml b/pyproject.toml index 0aa3e33..a90fbe1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,6 +33,7 @@ dependencies = [ "pyramid>=2", "pyramid_beaker", "pyramid_deform", + "pyramid_fanstatic", "pyramid_mako", "pyramid_tm", "waitress", diff --git a/src/wuttaweb/app.py b/src/wuttaweb/app.py index 6aadc0c..bafc921 100644 --- a/src/wuttaweb/app.py +++ b/src/wuttaweb/app.py @@ -110,7 +110,12 @@ 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('fanstatic.versioning', 'true') + settings.setdefault('mako.directories', ['wuttaweb:templates']) settings.setdefault('pyramid_deform.template_search_path', 'wuttaweb:templates/deform') @@ -119,8 +124,14 @@ 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_fanstatic') pyramid_config.include('pyramid_mako') pyramid_config.include('pyramid_tm') @@ -143,8 +154,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..1ea6481 --- /dev/null +++ b/src/wuttaweb/templates/appinfo/configure.mako @@ -0,0 +1,177 @@ +## -*- coding: utf-8; -*- +<%inherit file="/configure.mako" /> + +<%def name="form_content()"> + +

Basics

+
+ + + + + + + + + Production Mode + + + +
+ +

Web Libraries

+
+ + <${b}-table :data="weblibs"> + + <${b}-table-column field="title" + label="Name" + v-slot="props"> + {{ props.row.title }} + + + <${b}-table-column field="configured_version" + label="Version" + v-slot="props"> + {{ props.row.configured_version || props.row.default_version }} + + + <${b}-table-column field="configured_url" + label="URL Override" + v-slot="props"> + {{ props.row.configured_url }} + + + <${b}-table-column field="live_url" + label="Effective (Live) URL" + v-slot="props"> + + save settings and refresh page to see new URL + + + {{ props.row.live_url }} + + + + <${b}-table-column field="actions" + label="Actions" + v-slot="props"> + + % if request.use_oruga: + + % else: + + % endif + Edit + + + + + + % for weblib in weblibs or []: + ${h.hidden('wuttaweb.libver.{}'.format(weblib['key']), **{':value': "simpleSettings['wuttaweb.libver.{}']".format(weblib['key'])})} + ${h.hidden('wuttaweb.liburl.{}'.format(weblib['key']), **{':value': "simpleSettings['wuttaweb.liburl.{}']".format(weblib['key'])})} + % endfor + + <${b}-modal has-modal-card + % if request.use_oruga: + v-model:active="editWebLibraryShowDialog" + % else: + :active.sync="editWebLibraryShowDialog" + % endif + > + + + +
+ + +<%def name="modify_this_page_vars()"> + ${parent.modify_this_page_vars()} + + + + +${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 @@ -