Auto-register all config pages, for dropdown in App Settings

This commit is contained in:
Lance Edgar 2021-12-15 00:00:46 -06:00
parent 6f62f141d2
commit ca57bd3572
4 changed files with 21 additions and 19 deletions

View file

@ -156,9 +156,23 @@ def make_pyramid_config(settings, configure_csrf=True):
config.add_directive('add_tailbone_permission_group', 'tailbone.auth.add_permission_group')
config.add_directive('add_tailbone_permission', 'tailbone.auth.add_permission')
# and some similar magic for config views
config.add_directive('add_tailbone_config_page', 'tailbone.app.add_config_page')
return config
def add_config_page(config, route_name, label):
"""
Register a config page for the app.
"""
def action():
pages = config.get_settings().get('tailbone_config_pages', [])
pages.append({'label': label, 'route': route_name})
config.add_settings({'tailbone_config_pages': pages})
config.action(None, action)
def establish_theme(settings):
rattail_config = settings['rattail_config']

View file

@ -70,8 +70,8 @@
<section class="modal-card-body">
<p class="block">
If you like we can remove all ${config_title}
settings from the DB.
If you like we can remove all settings for ${config_title}
from the DB.
</p>
<p class="block">
Note that the tool normally removes all settings first,

View file

@ -4281,6 +4281,8 @@ class MasterView(View):
config.add_view(cls, attr='configure',
route_name='{}.configure'.format(route_prefix),
permission='{}.configure'.format(permission_prefix))
config.add_tailbone_config_page('{}.configure'.format(route_prefix),
config_title)
# quickie (search)
if cls.supports_quickie_search:

View file

@ -125,23 +125,9 @@ class AppSettingsView(View):
if not current_group:
current_group = self.request.session.get('appsettings.current_group')
# TODO: this should come from somewhere else
possible_config_options = [
{'label': "DataSync",
'route': 'datasync.configure'},
{'label': "Email",
'route': 'emailprofiles.configure'},
{'label': "Importing / Exporting",
'route': 'importing.configure'},
{'label': "Products",
'route': 'products.configure'},
{'label': "Receiving",
'route': 'receiving.configure'},
{'label': "Reporting",
'route': 'report_output.configure'},
{'label': "Vendors",
'route': 'vendors.configure'},
]
possible_config_options = sorted(
self.request.registry.settings['tailbone_config_pages'],
key=lambda p: p['label'])
config_options = []
for option in possible_config_options: