Warning:
Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.
| File mako_caching.diff,
5.1 KB
(added by lambacck, 2 years ago) |
|
Fix mako caching problem
|
-
# HG changeset patch
# User Chris Lambacher <chris@kateandchris.net>
# Date 1266868943 18000
# Node ID db7a8350abe98958e92e4a9c43f58b3e4c220106
# Parent ba1403f922d011ea3c1ac4b842f3c80831c052e1
Fix module_directory missing in dotted names for Mako
Bug: 2395
diff -r ba1403f922d0 -r db7a8350abe9 tg/configuration.py
|
a
|
b
|
|
| 309 | 309 | """ |
| 310 | 310 | |
| 311 | 311 | from tg.render import render_mako |
| | 312 | |
| | 313 | compiled_dir = tg.config.get('templating.mako.compiled_templates_dir', None) |
| | 314 | if not compiled_dir: |
| | 315 | # Try each given templates path (when are they > 1 ?) for writability.. |
| | 316 | for template_path in self.paths['templates']: |
| | 317 | if os.access(template_path, os.W_OK): |
| | 318 | compiled_dir = template_path |
| | 319 | break # first match is as good as any |
| | 320 | |
| | 321 | # Last recourse: project-dir/data/templates (pylons' default directory) |
| | 322 | if not compiled_dir: |
| | 323 | root = os.path.dirname(os.path.abspath(self.package.__file__)) |
| | 324 | pylons_default_path = os.path.join(root, '../data/templates') |
| | 325 | if os.access(pylons_default_path, os.W_OK): |
| | 326 | compiled_dir = pylons_default_path |
| | 327 | |
| | 328 | if not compiled_dir: |
| | 329 | raise IOError("None of your templates directory, %s, are writable for compiled " |
| | 330 | "templates. Please set the templating.mako.compiled_templates_dir " |
| | 331 | "variable in your .ini file" % str(self.paths['templates'])) |
| | 332 | |
| 312 | 333 | |
| 313 | 334 | if not use_dotted_templatenames: |
| 314 | 335 | use_dotted_templatenames = asbool(config.get('use_dotted_templatenames', 'true')) |
| … |
… |
|
| 320 | 341 | config['pylons.app_globals'].mako_lookup = DottedTemplateLookup( |
| 321 | 342 | input_encoding='utf-8', output_encoding='utf-8', |
| 322 | 343 | imports=['from webhelpers.html import escape'], |
| 323 | | default_filters=['escape']) |
| | 344 | default_filters=['escape'], module_directory=compiled_dir) |
| 324 | 345 | |
| 325 | 346 | else: |
| 326 | 347 | # If no dotted names support was required we will just setup |
| 327 | 348 | # a file system based template lookup mechanism. |
| 328 | | compiled_dir = tg.config.get('templating.mako.compiled_templates_dir', None) |
| 329 | 349 | |
| 330 | | if not compiled_dir: |
| 331 | | # Try each given templates path (when are they > 1 ?) for writability.. |
| 332 | | for template_path in self.paths['templates']: |
| 333 | | if os.access(template_path, os.W_OK): |
| 334 | | compiled_dir = template_path |
| 335 | | break # first match is as good as any |
| 336 | | |
| 337 | | # Last recourse: project-dir/data/templates (pylons' default directory) |
| 338 | | if not compiled_dir: |
| 339 | | root = os.path.dirname(os.path.abspath(self.package.__file__)) |
| 340 | | pylons_default_path = os.path.join(root, '../data/templates') |
| 341 | | if os.access(pylons_default_path, os.W_OK): |
| 342 | | compiled_dir = pylons_default_path |
| 343 | | |
| 344 | | if not compiled_dir: |
| 345 | | raise IOError("None of your templates directory, %s, are writable for compiled " |
| 346 | | "templates. Please set the templating.mako.compiled_templates_dir " |
| 347 | | "variable in your .ini file" % str(self.paths['templates'])) |
| 348 | | |
| 349 | 350 | from mako.lookup import TemplateLookup |
| 350 | 351 | config['pylons.app_globals'].mako_lookup = TemplateLookup( |
| 351 | 352 | directories=self.paths['templates'], |
-
diff -r ba1403f922d0 -r db7a8350abe9 tg/dottednames/mako_lookup.py
|
a
|
b
|
|
| 36 | 36 | """ |
| 37 | 37 | |
| 38 | 38 | def __init__(self, input_encoding, output_encoding, |
| 39 | | imports, default_filters): |
| | 39 | imports, default_filters, module_directory=None): |
| 40 | 40 | |
| 41 | 41 | self.input_encoding = input_encoding |
| 42 | 42 | self.output_encoding = output_encoding |
| … |
… |
|
| 46 | 46 | self.template_cache = dict() |
| 47 | 47 | # implement a cache for the filename lookups |
| 48 | 48 | self.template_filenames_cache = dict() |
| | 49 | self.module_directory = module_directory |
| 49 | 50 | |
| 50 | 51 | # a mutex to ensure thread safeness during template loading |
| 51 | 52 | self._mutex = threading.Lock() |
| … |
… |
|
| 131 | 132 | pass |
| 132 | 133 | |
| 133 | 134 | try: |
| 134 | | self.template_cache[filename] = Template(open(filename).read(), |
| | 135 | self.template_cache[filename] = Template( |
| 135 | 136 | filename=filename, |
| 136 | 137 | input_encoding=self.input_encoding, |
| 137 | 138 | output_encoding=self.output_encoding, |
| 138 | 139 | default_filters=self.default_filters, |
| 139 | 140 | imports=self.imports, |
| | 141 | module_directory=self.module_directory, |
| 140 | 142 | lookup=self) |
| 141 | 143 | |
| 142 | 144 | return self.template_cache[filename] |
Download in other formats: