##// END OF EJS Templates
configurator: reorganize the code
ergo -
Show More
@@ -42,7 +42,8 b' from redlock import Redlock'
42 42 from sqlalchemy import engine_from_config
43 43
44 44 from appenlight.celery import configure_celery
45 from appenlight.lib.configurator import CythonCompatConfigurator
45 from appenlight.lib.configurator import (CythonCompatConfigurator,
46 register_appenlight_plugin)
46 47 from appenlight.lib import cache_regions
47 48 from appenlight.lib.ext_json import json
48 49 from appenlight.security import groupfinder, AuthTokenAuthenticationPolicy
@@ -96,6 +97,13 b' def main(global_config, **settings):'
96 97 authorization_policy=authorization_policy,
97 98 root_factory='appenlight.security.RootFactory',
98 99 default_permission='view')
100 # custom registry variables
101
102 # resource type information
103 config.registry.resource_types = ['resource', 'application']
104 # plugin information
105 config.registry.appenlight_plugins = {}
106
99 107 config.set_default_csrf_options(require_csrf=True, header='X-XSRF-TOKEN')
100 108 config.add_view_deriver('appenlight.predicates.csrf_view',
101 109 name='csrf_view')
@@ -177,44 +185,9 b' def main(global_config, **settings):'
177 185
178 186 config.include('appenlight.views')
179 187 config.include('appenlight.views.admin')
180 config.scan(ignore=['appenlight.migrations',
181 'appenlight.scripts',
188 config.scan(ignore=['appenlight.migrations', 'appenlight.scripts',
182 189 'appenlight.tests'])
183 190
184 # resource type information
185 config.registry.resource_types = ['resource', 'application']
186
187 # plugin information
188 config.registry.appenlight_plugins = {}
189
190 def register_appenlight_plugin(config, plugin_name, plugin_config):
191 def register():
192 log.warning('Registering plugin: {}'.format(plugin_name))
193 if plugin_name not in config.registry.appenlight_plugins:
194 config.registry.appenlight_plugins[plugin_name] = {
195 'javascript': None,
196 'static': None,
197 'css': None,
198 'top_nav': None,
199 'celery_tasks': None,
200 'celery_beats': None,
201 'fulltext_indexer': None,
202 'sqlalchemy_migrations': None,
203 'default_values_setter': None,
204 'resource_types': [],
205 'url_gen': None
206 }
207 config.registry.appenlight_plugins[plugin_name].update(
208 plugin_config)
209 # inform AE what kind of resource types we have available
210 # so we can avoid failing when a plugin is removed but data
211 # is still present in the db
212 if plugin_config.get('resource_types'):
213 config.registry.resource_types.extend(
214 plugin_config['resource_types'])
215
216 config.action('appenlight_plugin={}'.format(plugin_name), register)
217
218 191 config.add_directive('register_appenlight_plugin',
219 192 register_appenlight_plugin)
220 193
@@ -1,7 +1,9 b''
1 1 import inspect
2 import logging
2 3
3 4 from pyramid.config import Configurator
4 5
6 log = logging.getLogger(__name__)
5 7
6 8 class InspectProxy(object):
7 9 """
@@ -59,3 +61,32 b' class CythonCompatConfigurator(Configurator):'
59 61 a custom one that is cython compatible.
60 62 """
61 63 inspect = InspectProxy()
64
65
66 def register_appenlight_plugin(config, plugin_name, plugin_config):
67 def register():
68 log.warning('Registering plugin: {}'.format(plugin_name))
69 if plugin_name not in config.registry.appenlight_plugins:
70 config.registry.appenlight_plugins[plugin_name] = {
71 'javascript': None,
72 'static': None,
73 'css': None,
74 'top_nav': None,
75 'celery_tasks': None,
76 'celery_beats': None,
77 'fulltext_indexer': None,
78 'sqlalchemy_migrations': None,
79 'default_values_setter': None,
80 'resource_types': [],
81 'url_gen': None
82 }
83 config.registry.appenlight_plugins[plugin_name].update(
84 plugin_config)
85 # inform AE what kind of resource types we have available
86 # so we can avoid failing when a plugin is removed but data
87 # is still present in the db
88 if plugin_config.get('resource_types'):
89 config.registry.resource_types.extend(
90 plugin_config['resource_types'])
91
92 config.action('appenlight_plugin={}'.format(plugin_name), register)
General Comments 0
You need to be logged in to leave comments. Login now