Commits

imbolc committed f514105

use jinja2.enviroment.globals

  • Participants
  • Parent commits 3f12f37

Comments (0)

Files changed (4)

File pysi/config.py

 # -*- coding: utf-8 -*-
 
-
 class Cfg(object):
     DEBUG = False
     BASIC_AUTH_SSL_ONLY = False  # basic-авторизация только по https
     FLASH_COOKIE_NAME = u'pysi.flash'
     ROUTING_QUEUE = ['pysi.auto_routing']  # очередь функций роутинга
     JINJA2_EXTENSIONS = ['jinja2.ext.with_']
+    JINJA2_GLOBALS = {}
 
     STATIC_PATH = 'static'
     STATIC_URL_PREFIX  = '/static/'

File pysi/template.py

 @cached_function
 def _env():
     import jinja2
-    return jinja2.Environment(
+    import pysi
+
+    env = jinja2.Environment(
         loader = jinja2.FunctionLoader(obj_from_str(cfg.TEMPLATE_LOADER)),
         autoescape = True,
         cache_size = cfg.TEMPLATE_CACHE_SIZE,
         auto_reload = cfg.TEMPLATE_AUTO_RELOAD,
         extensions = cfg.JINJA2_EXTENSIONS,
     )
+    env.globals = cfg.JINJA2_GLOBALS or {
+            'url4': pysi.url4,
+            'cfg': pysi.cfg,
+            'static_url': pysi.static_url,
+
+            'xrange': xrange,
+            'enumerate': enumerate,
+            'len': len,
+    }
+    return env
 
 class FileLoader(object):
     mtimes = {}

File pysi/wsgi.py

 
     @cached_property
     def context(self):
-        res = {'rq': self, 'url4': url4, 'cfg': cfg, 'static_url': static_url}
+        res = {'rq': self}
         for func in cfg.CONTEXT_PROCESSORS:
             res.update(func(self))
         return res
 import os
 from setuptools import setup
 
-VERSION = '0.17.1'
+VERSION = '0.18.0'
 PACKAGE = 'pysi'
 
 if __name__ == '__main__':