Add first experiment with websockets, for datasync status page
This commit is contained in:
parent
065f845707
commit
2375733d0f
9 changed files with 414 additions and 17 deletions
|
@ -129,6 +129,9 @@ def make_pyramid_config(settings, configure_csrf=True):
|
|||
settings.setdefault('pyramid_deform.template_search_path', 'tailbone:templates/deform')
|
||||
config = Configurator(settings=settings, root_factory=Root)
|
||||
|
||||
# add rattail config directly to registry
|
||||
config.registry['rattail_config'] = rattail_config
|
||||
|
||||
# configure user authorization / authentication
|
||||
config.set_authorization_policy(TailboneAuthorizationPolicy())
|
||||
config.set_authentication_policy(SessionAuthenticationPolicy())
|
||||
|
@ -175,9 +178,45 @@ def make_pyramid_config(settings, configure_csrf=True):
|
|||
config.add_directive('add_tailbone_index_page', 'tailbone.app.add_index_page')
|
||||
config.add_directive('add_tailbone_config_page', 'tailbone.app.add_config_page')
|
||||
|
||||
config.add_directive('add_tailbone_websocket', 'tailbone.app.add_websocket')
|
||||
|
||||
return config
|
||||
|
||||
|
||||
def add_websocket(config, name, view, attr=None):
|
||||
"""
|
||||
Register a websocket entry point for the app.
|
||||
"""
|
||||
def action():
|
||||
rattail_config = config.registry.settings['rattail_config']
|
||||
rattail_app = rattail_config.get_app()
|
||||
|
||||
if isinstance(view, six.string_types):
|
||||
view_callable = rattail_app.load_object(view)
|
||||
else:
|
||||
view_callable = view
|
||||
view_callable = view_callable(config.registry)
|
||||
if attr:
|
||||
view_callable = getattr(view_callable, attr)
|
||||
|
||||
path = '/ws/{}'.format(name)
|
||||
|
||||
# register route
|
||||
config.add_route('ws.{}'.format(name),
|
||||
path,
|
||||
static=True)
|
||||
|
||||
# register view callable
|
||||
websockets = config.registry.setdefault('tailbone_websockets', {})
|
||||
websockets[path] = view_callable
|
||||
|
||||
config.action('tailbone-add-websocket', action,
|
||||
# nb. since this action adds routes, it must happen
|
||||
# sooner in the order than it normally would, hence
|
||||
# we declare that
|
||||
order=-20)
|
||||
|
||||
|
||||
def add_index_page(config, route_name, label, permission):
|
||||
"""
|
||||
Register a config page for the app.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue