"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "roundup/cgi/engine_jinja2.py" between
roundup-1.6.1.tar.gz and roundup-2.0.0.tar.gz

About: Roundup is an highly customisable issue-tracking system with command-line, web and e-mail interfaces (written in Python).

engine_jinja2.py  (roundup-1.6.1):engine_jinja2.py  (roundup-2.0.0)
skipping to change at line 25 skipping to change at line 25
TRACKER_HOME/templates/INFO.txt TRACKER_HOME/templates/INFO.txt
describing how the dir was created, for example describing how the dir was created, for example
"This is a copy of 'classic' template from ..." "This is a copy of 'classic' template from ..."
also template fallback mechanizm for multi-engine also template fallback mechanizm for multi-engine
configuration configuration
[ ] backward compatibility - if no engine is explicitly [ ] backward compatibility - if no engine is explicitly
specified, use TRACKER_HOME/html directory specified, use TRACKER_HOME/html directory
[ ] copy TEMPLATES-INFO.txt to INFO.txt [ ] copy TEMPLATES-INFO.txt to INFO.txt
[ ] implement VERSION file in environment for auto [ ] implement VERSION file in environment for auto
upgrade upgrade
[ ] figure out what to do with autoescaping - it is disabled
by default in Jinja2
[ ] precompile() is a stub [ ] precompile() is a stub
[ ] add {{ debug() }} dumper to inspect available variables [ ] add {{ debug() }} dumper to inspect available variables
https://github.com/mitsuhiko/jinja2/issues/174 https://github.com/mitsuhiko/jinja2/issues/174
""" """
from __future__ import print_function
import jinja2 import jinja2
import gettext import gettext
import mimetypes
from types import MethodType import sys
# http://jinja.pocoo.org/docs/api/#loaders # http://jinja.pocoo.org/docs/api/#loaders
from roundup.cgi.templating import context, LoaderBase, TemplateBase from roundup.cgi.templating import context, LoaderBase, TemplateBase
from roundup.anypy.strings import s2u
class Jinja2Loader(LoaderBase): class Jinja2Loader(LoaderBase):
def __init__(self, dir): def __init__(self, dir):
extensions = [
'jinja2.ext.autoescape',
]
print "Jinja2 templates: ", dir
print "Extensions: ", extensions
self._env = jinja2.Environment( self._env = jinja2.Environment(
loader=jinja2.FileSystemLoader(dir), loader=jinja2.FileSystemLoader(dir),
extensions=extensions extensions=['jinja2.ext.i18n'],
) autoescape=True
)
# Adding a custom filter that can transform roundup's vars to unicode # Adding a custom filter that can transform roundup's vars to unicode
# This is necessary because jinja2 can only deal with unicode objects # This is necessary because jinja2 can only deal with unicode objects
# and roundup uses utf-8 for the internal representation. # and roundup uses utf-8 for the internal representation.
# The automatic conversion will assume 'ascii' and fail sometime. # The automatic conversion will assume 'ascii' and fail sometime.
# Analysed with roundup 1.5.0 and jinja 2.7.1. See issue2550811. # Analysed with roundup 1.5.0 and jinja 2.7.1. See issue2550811.
self._env.filters["u"] = lambda s: \ self._env.filters["u"] = s2u
unicode(s(), "utf-8") if type(s) == MethodType \
else unicode(s, "utf-8") def _find(self, tplname):
for extension in ('', '.html', '.xml'):
try:
filename = tplname + extension
return self._env.get_template(filename)
except jinja2.TemplateNotFound:
continue
return None
def check(self, tplname): def check(self, tplname):
#print tplname return bool(self._find(tplname))
try:
#print self._env.get_template(tplname + '.html')
self._env.get_template(tplname + '.html')
except jinja2.TemplateNotFound:
return
else:
return True
def load(self, tplname): def load(self, tplname):
#src, filename = self.check(tplname) tpl = self._find(tplname)
return Jinja2ProxyPageTemplate(self._env.get_template(tplname + '.html') pt = Jinja2ProxyPageTemplate(tpl)
) pt.content_type = mimetypes.guess_type(tpl.filename)[0] or 'text/html'
return pt
def precompile(self): def precompile(self):
pass pass
class Jinja2ProxyPageTemplate(TemplateBase): class Jinja2ProxyPageTemplate(TemplateBase):
def __init__(self, template): def __init__(self, template):
self._tpl = template self._tpl = template
def render(self, client, classname, request, **options): def render(self, client, classname, request, **options):
# [ ] limit the information passed to the minimal necessary set # [ ] limit the information passed to the minimal necessary set
c = context(client, self, classname, request) c = context(client, self, classname, request)
c.update({'options': options})
return self._tpl.render(c).encode(client.charset, ) c.update({'options': options,
'gettext': lambda s: s2u(client.gettext(s)),
'ngettext': lambda s, p, n: s2u(client.ngettext(s, p, n))})
s = self._tpl.render(c)
return s if sys.version_info[0] > 2 else \
s.encode(client.STORAGE_CHARSET, )
def __getitem__(self, name): def __getitem__(self, name):
# [ ] figure out what are these for # [ ] figure out what are these for
raise NotImplemented raise NotImplementedError
#return self._pt[name] # return self._pt[name]
def __getattr__(self, name): def __getattr__(self, name):
# [ ] figure out what are these for # [ ] figure out what are these for
raise NotImplemented raise NotImplementedError
#return getattr(self._pt, name) # return getattr(self._pt, name)
 End of changes. 12 change blocks. 
30 lines changed or deleted 33 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)