Skip to content
Browse files

Merge branch 'development' of https://github.com/TurboGears/tg2 into …

…development
  • Loading branch information...
2 parents 22366ba + e75e59d commit cea70d7ec1dfd24d04f7d429c02514215cca3137 @amol- amol- committed Oct 21, 2012
Showing with 21 additions and 29 deletions.
  1. +21 −29 tg/configuration/app_config.py
View
50 tg/configuration/app_config.py
@@ -8,7 +8,7 @@
import mimetypes
from UserDict import DictMixin
-from pylons.i18n import ugettext
+from pylons.i18n import ugettext, get_lang
from pylons.configuration import config as pylons_config
from beaker.middleware import SessionMiddleware, CacheMiddleware
@@ -359,35 +359,26 @@ def setup_mako_renderer(self, use_dotted_templatenames=None):
# a file system based template lookup mechanism.
compiled_dir = tg.config.get('templating.mako.compiled_templates_dir', None)
- if not compiled_dir:
- # Try each given templates path (when are they > 1 ?) for writability..
- for template_path in self.paths['templates']:
- if os.access(template_path, os.W_OK):
- compiled_dir = template_path
- break # first match is as good as any
-
- # Last recourse: project-dir/data/templates (pylons' default directory)
- if not compiled_dir:
+ if not compiled_dir or compiled_dir.lower() in ('none', 'false'):
+ # Cache compiled templates in-memory
+ compiled_dir = None
+ else:
+ bad_path = None
+ if os.path.exists(compiled_dir):
+ if not os.access(compiled_dir, os.W_OK):
+ bad_path = compiled_dir
+ compiled_dir = None
+ else:
try:
- root = os.path.dirname(os.path.abspath(self.package.__file__))
- except AttributeError:
- # Thrown during unit tests when self.package.__file__ doesn't exist
- root = None
-
- if root:
- pylons_default_path = os.path.join(root, '../data/templates')
- if os.access(pylons_default_path, os.W_OK):
- compiled_dir = pylons_default_path
-
- if not compiled_dir:
- if use_dotted_templatenames:
- # Gracefully digress to in-memory template caching
- pass
- else:
- raise IOError("None of your templates directory, %s, are "
- "writable for compiled templates. Please set the "
- "templating.mako.compiled_templates_dir variable in your "
- ".ini file" % str(self.paths['templates']))
+ os.makedirs(compiled_dir)
+ except:
+ bad_path = compiled_dir
+ compiled_dir = None
+ if bad_path:
+ log.warn("Unable to write cached templates to %r; falling back "
+ "to an in-memory cache. Please set the `templating.mak"
+ "o.compiled_templates_dir` configuration option to a "
+ "writable directory." % bad_path)
if use_dotted_templatenames:
# Support dotted names by injecting a slightly different template
@@ -862,6 +853,7 @@ def add_tosca2_middleware(self, app):
default_tw2_config = dict( default_engine=self.default_renderer,
preferred_rendering_engines=tw2_engines,
translator=ugettext,
+ get_lang=get_lang,
auto_reload_templates=self.auto_reload_templates,
controller_prefix='/tw2/controllers/',
res_prefix='/tw2/resources/',

0 comments on commit cea70d7

Please sign in to comment.
Something went wrong with that request. Please try again.