Add the "provider" concept, let them configure db sessions
more to come...
This commit is contained in:
parent
57f3b942e5
commit
c4e872c94c
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2020 Lance Edgar
|
||||
# Copyright © 2010-2022 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -45,6 +45,7 @@ import tailbone.db
|
|||
from tailbone.auth import TailboneAuthorizationPolicy
|
||||
from tailbone.config import csrf_token_name, csrf_header_name
|
||||
from tailbone.util import get_effective_theme, get_theme_template_path
|
||||
from tailbone.providers import get_all_providers
|
||||
|
||||
|
||||
def make_rattail_config(settings):
|
||||
|
@ -115,6 +116,8 @@ def make_pyramid_config(settings, configure_csrf=True):
|
|||
"""
|
||||
Make a Pyramid config object from the given settings.
|
||||
"""
|
||||
rattail_config = settings['rattail_config']
|
||||
|
||||
config = settings.pop('pyramid_config', None)
|
||||
if config:
|
||||
config.set_root_factory(Root)
|
||||
|
@ -132,7 +135,6 @@ def make_pyramid_config(settings, configure_csrf=True):
|
|||
|
||||
# maybe require CSRF token protection
|
||||
if configure_csrf:
|
||||
rattail_config = settings['rattail_config']
|
||||
config.set_default_csrf_options(require_csrf=True,
|
||||
token=csrf_token_name(rattail_config),
|
||||
header=csrf_header_name(rattail_config))
|
||||
|
@ -152,6 +154,11 @@ def make_pyramid_config(settings, configure_csrf=True):
|
|||
else:
|
||||
config.include('pyramid_retry')
|
||||
|
||||
# configure DB sessions associated with transaction manager
|
||||
providers = get_all_providers(rattail_config)
|
||||
for provider in six.itervalues(providers):
|
||||
provider.configure_db_sessions(rattail_config, config)
|
||||
|
||||
# Add some permissions magic.
|
||||
config.add_directive('add_tailbone_permission_group', 'tailbone.auth.add_permission_group')
|
||||
config.add_directive('add_tailbone_permission', 'tailbone.auth.add_permission')
|
||||
|
|
56
tailbone/providers.py
Normal file
56
tailbone/providers.py
Normal file
|
@ -0,0 +1,56 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2022 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
# Rattail is free software: you can redistribute it and/or modify it under the
|
||||
# terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation, either version 3 of the License, or (at your option) any later
|
||||
# version.
|
||||
#
|
||||
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# Rattail. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
"""
|
||||
Providers for Tailbone features
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
from rattail.util import load_entry_points
|
||||
|
||||
|
||||
class TailboneProvider(object):
|
||||
"""
|
||||
Base class for Tailbone providers. These are responsible for
|
||||
declaring which things a given project makes available to the app.
|
||||
(Or at least the things which should be easily configurable.)
|
||||
"""
|
||||
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
|
||||
def configure_db_sessions(self, rattail_config, pyramid_config):
|
||||
pass
|
||||
|
||||
def get_provided_views(self):
|
||||
return {}
|
||||
|
||||
|
||||
def get_all_providers(config):
|
||||
"""
|
||||
Returns a dict of all registered providers.
|
||||
"""
|
||||
providers = load_entry_points('tailbone.providers')
|
||||
for key in list(providers):
|
||||
providers[key] = providers[key](config)
|
||||
return providers
|
Loading…
Reference in a new issue