Permalink
Browse files

Make possible to import controllers (and so expose templates) before …

…AppConfig.init_config has been called
  • Loading branch information...
1 parent 5bff3d6 commit ed3616d76bad98dcd09b54e66a0ae00c60fcc5f6 @amol- amol- committed Sep 3, 2012
Showing with 16 additions and 1 deletion.
  1. +11 −0 tg/configuration/app_config.py
  2. +5 −1 tg/decorators.py
View
11 tg/configuration/app_config.py
@@ -153,6 +153,17 @@ def __init__(self):
#override this variable to customize how the tw2 middleware is set up
self.custom_tw2_config = {}
+ def __setitem__(self, key, value):
+ #some entries are required at application setup time
+ #so we need to keep them in sync between tg.config and AppConfig.
+
+ #This is especially true for available renderers which enable
+ #engine check in tg.decorators.Decorator.register_template_engine
+ if key in ['default_renderer', 'renderers']:
+ config[key] = value
+ return super(AppConfig, self).__setattr__(key, value)
+ __setattr__ = __setitem__
+
def get_root_module(self):
root_module_path = self.paths['root']
base_controller_path = self.paths['controllers']
View
6 tg/decorators.py
@@ -103,7 +103,11 @@ def register_template_engine(self,
default_renderer = config.get('default_renderer')
available_renderers = config.get('renderers', [])
- if engine and engine not in available_renderers:
+ if engine and not available_renderers:
+ log.warn('Renderers not registered yet while exposing template %s for engine %s, '
+ 'skipping engine availability check', template, engine)
+
+ if engine and available_renderers and engine not in available_renderers:
log.debug('Registering template %s for engine %s not available. Skipping it', template, engine)
return

0 comments on commit ed3616d

Please sign in to comment.