Anonymous avatar Anonymous committed e40e7dd

Just use a method decorated by property for jinja2 lazy loading.

Comments (0)

Files changed (1)

     return app
-class LazyJinja2Env(object):
-  def __get__(self, kay_app, obj_type=None):
-    if not hasattr(kay_app, '_jinja2_env'):
-      kay_app.init_jinja2_environ()
-    if hasattr(kay_app, 'active_translations'):
-      if kay_app.app_settings.USE_I18N:
-        kay_app._jinja2_env.install_gettext_translations(
-          kay_app.active_translations)
-      else:
-        kay_app._jinja2_env.globals.update(
-          _=lambda x: x,
-          gettext=lambda x: x,
-          ngettext=lambda s, p, n: (n != 1 and (p,) or (s,))[0]
-        )
-    return kay_app._jinja2_env
 class KayApp(object):
   def __init__(self, app_settings):
     self._request_middleware = self._response_middleware = \
         self._view_middleware = self._exception_middleware = None
     self.auth_backend = None
-    self.__class__.jinja2_env = LazyJinja2Env()
+  @property
+  def jinja2_env(self):
+    if not hasattr(self, '_jinja2_env'):
+      self.init_jinja2_environ()
+    if hasattr(self, 'active_translations'):
+      if self.app_settings.USE_I18N:
+        self._jinja2_env.install_gettext_translations(self.active_translations)
+      else:
+        self._jinja2_env.globals.update(
+          _=lambda x: x,
+          gettext=lambda x: x,
+          ngettext=lambda s, p, n: (n != 1 and (p,) or (s,))[0]
+        )
+    return self._jinja2_env
   def get_mount_point(self, app):
     if app == 'kay._internal':
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.