Coverage for .tox / coverage / lib / python3.11 / site-packages / wuttaweb / conf.py: 100%
12 statements
« prev ^ index » next coverage.py v7.13.1, created at 2025-12-31 19:25 -0600
« prev ^ index » next coverage.py v7.13.1, created at 2025-12-31 19:25 -0600
1# -*- coding: utf-8; -*-
2################################################################################
3#
4# wuttaweb -- Web App for Wutta Framework
5# Copyright © 2024-2025 Lance Edgar
6#
7# This file is part of Wutta Framework.
8#
9# Wutta Framework is free software: you can redistribute it and/or modify it
10# under the terms of the GNU General Public License as published by the Free
11# Software Foundation, either version 3 of the License, or (at your option) any
12# later version.
13#
14# Wutta Framework is distributed in the hope that it will be useful, but
15# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17# more details.
18#
19# You should have received a copy of the GNU General Public License along with
20# Wutta Framework. If not, see <http://www.gnu.org/licenses/>.
21#
22################################################################################
23"""
24Config Extension
25"""
27from wuttjamaican.conf import WuttaConfigExtension
30class WuttaWebConfigExtension(WuttaConfigExtension):
31 """
32 Config extension for WuttaWeb.
34 This sets the default plugin used for SQLAlchemy-Continuum, to
35 :class:`~wuttaweb.db.continuum.WuttaWebContinuumPlugin`. Which is
36 only relevant if Wutta-Continuum is installed and enabled. For
37 more info see :doc:`wutta-continuum:index`.
38 """
40 key = "wuttaweb"
42 def configure(self, config): # pylint: disable=empty-docstring
43 """ """
44 config.setdefault(
45 "wutta_continuum.wutta_plugin_spec",
46 "wuttaweb.db.continuum:WuttaWebContinuumPlugin",
47 )
50def add_master_view(config, master):
51 """
52 Pyramid directive to add the given ``MasterView`` subclass to the
53 app's registry.
55 This allows the app to dynamically present certain options for
56 admin features etc.
58 This is normally called automatically for all master views, within
59 the :meth:`~wuttaweb.views.master.MasterView.defaults()` method.
61 Should you need to call this yourself, do not call it directly but
62 instead make a similar call via the Pyramid config object::
64 pyramid_config.add_wutta_master_view(PoserWidgetView)
66 :param config: Reference to the Pyramid config object.
68 :param master: Reference to a
69 :class:`~wuttaweb.views.master.MasterView` subclass.
71 This function is involved in app startup; once that phase is
72 complete you can inspect the master views like so::
74 master_views = request.registry.settings["wuttaweb_master_views"]
76 # find master views for given model class
77 user_views = master_views.get(model.User, [])
79 # some master views are registered by model name instead (if no class)
80 email_views = master_views.get("email_setting", [])
81 """
82 key = master.get_model_class() or master.get_model_name()
84 def action():
85 master_views = config.get_settings().get("wuttaweb_master_views", {})
86 master_views.setdefault(key, []).append(master)
87 config.add_settings({"wuttaweb_master_views": master_views})
89 config.action(None, action)