[Mpuls-commits] r2943 - base/trunk/mpulsweb/lib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Jun 9 14:21:47 CEST 2010


Author: torsten
Date: 2010-06-09 14:21:46 +0200 (Wed, 09 Jun 2010)
New Revision: 2943

Modified:
   base/trunk/mpulsweb/lib/base.py
Log:
Added new function which uses own translator for template rendering



Modified: base/trunk/mpulsweb/lib/base.py
===================================================================
--- base/trunk/mpulsweb/lib/base.py	2010-06-09 11:40:46 UTC (rev 2942)
+++ base/trunk/mpulsweb/lib/base.py	2010-06-09 12:21:46 UTC (rev 2943)
@@ -38,11 +38,14 @@
 from pylons import c, config, g, request, response, session
 from pylons.controllers import WSGIController
 from pylons.controllers.util import redirect_to
-from pylons.i18n import _
-from pylons.templating import render_mako as render
+#from pylons.i18n import _
+#from pylons.templating import render_mako as render
+from pylons.templating import cached_template, pylons_globals 
 
+from webhelpers.html import literal
+
 import mpulsweb.lib.db as db
-from mpulsweb.lib.translation import set_lang
+from mpulsweb.lib.translation import set_lang, _
 from mpulsweb.lib.timelog import timeLog
 from mpulsweb.lib.navigation import get_navigation
 
@@ -64,11 +67,41 @@
 
 log = logging.getLogger(__name__)
 
+# Added own render_mako function which addes custom translation functions
+def render_mako(template_name, extra_vars=None, cache_key=None, 
+                cache_type=None, cache_expire=None):
+    """Render a template with Mako
+    
+    Accepts the cache options ``cache_key``, ``cache_type``, and
+    ``cache_expire``.
+    
+    """    
+    # Create a render callable for the cache function
+    def render_template():
+        log.debug('rendering')
+        # Pull in extra vars if needed
+        globs = extra_vars or {}
+        
+        # Second, get the globals
+        globs.update(pylons_globals())
 
+        # Thirs overwritw '_'
+        globs.update({'_': _})
+
+        # Grab a template reference
+        template = globs['app_globals'].mako_lookup.get_template(template_name)
+        
+        return literal(template.render_unicode(**globs))
+    
+    return cached_template(template_name, render_template, cache_key=cache_key,
+                           cache_type=cache_type, cache_expire=cache_expire)
+render = render_mako
+
 class BaseController(WSGIController):
 
     def __init__(self):
         self.db = None
+        log.debug(_('Testuebersetzung'))
         self.page_cache = None
 
     def _loadCase(self, id):



More information about the Mpuls-commits mailing list