django-jinja-2.1.2/ 0000755 0001750 0000144 00000000000 12653222617 014202 5 ustar niwi users 0000000 0000000 django-jinja-2.1.2/django_jinja/ 0000755 0001750 0000144 00000000000 12653222617 016617 5 ustar niwi users 0000000 0000000 django-jinja-2.1.2/django_jinja/builtins/ 0000755 0001750 0000144 00000000000 12653222617 020450 5 ustar niwi users 0000000 0000000 django-jinja-2.1.2/django_jinja/builtins/__init__.py 0000644 0001750 0000144 00000000762 12520361635 022563 0 ustar niwi users 0000000 0000000 DEFAULT_EXTENSIONS = [
"jinja2.ext.do",
"jinja2.ext.loopcontrols",
"jinja2.ext.with_",
"jinja2.ext.i18n",
"jinja2.ext.autoescape",
"django_jinja.builtins.extensions.CsrfExtension",
"django_jinja.builtins.extensions.CacheExtension",
"django_jinja.builtins.extensions.TimezoneExtension",
"django_jinja.builtins.extensions.UrlsExtension",
"django_jinja.builtins.extensions.StaticFilesExtension",
"django_jinja.builtins.extensions.DjangoFiltersExtension",
]
django-jinja-2.1.2/django_jinja/builtins/extensions.py 0000644 0001750 0000144 00000020770 12653222065 023224 0 ustar niwi users 0000000 0000000 from __future__ import unicode_literals
import traceback
import logging
import django
from django.conf import settings
from django.contrib.staticfiles.storage import staticfiles_storage
from django.core.cache import cache
from django.core.urlresolvers import NoReverseMatch
from django.core.urlresolvers import reverse
from django.utils.formats import localize
from django.utils.translation import pgettext
from django.utils.translation import ugettext
from jinja2 import Markup
from jinja2 import TemplateSyntaxError
from jinja2 import lexer
from jinja2 import nodes
from jinja2.ext import Extension
try:
from django.utils.encoding import force_text
from django.utils.encoding import force_bytes
except ImportError:
from django.utils.encoding import force_unicode as force_text
from django.utils.encoding import smart_str as force_bytes
JINJA2_MUTE_URLRESOLVE_EXCEPTIONS = getattr(settings, "JINJA2_MUTE_URLRESOLVE_EXCEPTIONS", False)
logger = logging.getLogger(__name__)
# Compatibility with django <= 1.5
if django.VERSION[:2] <= (1, 5):
import hashlib
from django.utils.http import urlquote
def make_template_fragment_key(fragm_name, vary_on):
args_map = map(urlquote, vary_on)
args_map = map(lambda x: force_bytes(x), args_map)
args_string = b':'.join(args_map)
args_hash = hashlib.md5(args_string).hexdigest()
return 'template.cache.{0}.{1}'.format(fragm_name, args_hash)
else:
from django.core.cache.utils import make_template_fragment_key
class CsrfExtension(Extension):
tags = set(['csrf_token'])
def __init__(self, environment):
self.environment = environment
def parse(self, parser):
lineno = parser.stream.expect('name:csrf_token').lineno
call = self.call_method(
'_render',
[nodes.Name('csrf_token', 'load', lineno=lineno)],
lineno=lineno
)
return nodes.Output([nodes.MarkSafe(call)])
def _render(self, csrf_token):
if csrf_token:
if csrf_token == 'NOTPROVIDED':
return Markup("")
return Markup("" % (csrf_token))
if settings.DEBUG:
import warnings
warnings.warn("A {% csrf_token %} was used in a template, but the context"
"did not provide the value. This is usually caused by not "
"using RequestContext.")
return ''
class CacheExtension(Extension):
"""
Exactly like Django's own tag, but supports full Jinja2
expressiveness for all arguments.
{% cache gettimeout()*2 "foo"+options.cachename %}
...
{% endcache %}
General Syntax:
{% cache [expire_time] [fragment_name] [var1] [var2] .. %}
.. some expensive processing ..
{% endcache %}
Available by default (does not need to be loaded).
Partly based on the ``FragmentCacheExtension`` from the Jinja2 docs.
"""
tags = set(['cache'])
def parse(self, parser):
lineno = next(parser.stream).lineno
expire_time = parser.parse_expression()
fragment_name = parser.parse_expression()
vary_on = []
while not parser.stream.current.test('block_end'):
vary_on.append(parser.parse_expression())
body = parser.parse_statements(['name:endcache'], drop_needle=True)
return nodes.CallBlock(
self.call_method('_cache_support',
[expire_time, fragment_name,
nodes.List(vary_on), nodes.Const(lineno)]),
[], [], body).set_lineno(lineno)
def _cache_support(self, expire_time, fragm_name, vary_on, lineno, caller):
try:
expire_time = int(expire_time)
except (ValueError, TypeError):
raise TemplateSyntaxError('"%s" tag got a non-integer timeout '
'value: %r' % (list(self.tags)[0], expire_time), lineno)
cache_key = make_template_fragment_key(fragm_name, vary_on)
value = cache.get(cache_key)
if value is None:
value = caller()
cache.set(cache_key, force_text(value), expire_time)
else:
value = force_text(value)
return value
class StaticFilesExtension(Extension):
def __init__(self, environment):
super(StaticFilesExtension, self).__init__(environment)
environment.globals["static"] = self._static
def _static(self, path):
return staticfiles_storage.url(path)
class UrlsExtension(Extension):
def __init__(self, environment):
super(UrlsExtension, self).__init__(environment)
environment.globals["url"] = self._url_reverse
def _url_reverse(self, name, *args, **kwargs):
try:
return reverse(name, args=args, kwargs=kwargs)
except NoReverseMatch as exc:
logger.error('Error: %s', exc)
if not JINJA2_MUTE_URLRESOLVE_EXCEPTIONS:
raise
return ''
return reverse(name, args=args, kwargs=kwargs)
from . import filters
class TimezoneExtension(Extension):
def __init__(self, environment):
super(TimezoneExtension, self).__init__(environment)
environment.globals["utc"] = filters.utc
environment.globals["timezone"] = filters.timezone
environment.globals["localtime"] = filters.localtime
class DjangoFiltersExtension(Extension):
def __init__(self, environment):
super(DjangoFiltersExtension, self).__init__(environment)
environment.filters["static"] = filters.static
environment.filters["reverseurl"] = filters.reverse
environment.filters["addslashes"] = filters.addslashes
environment.filters["capfirst"] = filters.capfirst
environment.filters["escapejs"] = filters.escapejs_filter
environment.filters["floatformat"] = filters.floatformat
environment.filters["iriencode"] = filters.iriencode
environment.filters["linenumbers"] = filters.linenumbers
environment.filters["make_list"] = filters.make_list
environment.filters["slugify"] = filters.slugify
environment.filters["stringformat"] = filters.stringformat
environment.filters["truncatechars"] = filters.truncatechars
environment.filters["truncatewords"] = filters.truncatewords
environment.filters["truncatewords_html"] = filters.truncatewords_html
environment.filters["urlizetrunc"] = filters.urlizetrunc
environment.filters["ljust"] = filters.ljust
environment.filters["rjust"] = filters.rjust
environment.filters["cut"] = filters.cut
environment.filters["linebreaksbr"] = filters.linebreaksbr
environment.filters["linebreaks"] = filters.linebreaks_filter
environment.filters["removetags"] = filters.removetags
environment.filters["striptags"] = filters.striptags
environment.filters["add"] = filters.add
environment.filters["date"] = filters.date
environment.filters["time"] = filters.time
environment.filters["timesince"] = filters.timesince_filter
environment.filters["timeuntil"] = filters.timeuntil_filter
environment.filters["default_if_none"] = filters.default_if_none
environment.filters["divisibleby"] = filters.divisibleby
environment.filters["yesno"] = filters.yesno
environment.filters["pluralize"] = filters.pluralize
environment.filters["localtime"] = filters.localtime
environment.filters["utc"] = filters.utc
environment.filters["timezone"] = filters.timezone
class DjangoExtraFiltersExtension(Extension):
def __init__(self, environment):
super(DjangoExtraFiltersExtension, self).__init__(environment)
environment.filters["title"] = filters.title
environment.filters["upper"] = filters.upper
environment.filters["lower"] = filters.lower
environment.filters["urlencode"] = filters.urlencode
environment.filters["urlize"] = filters.urlize
environment.filters["wordcount"] = filters.wordcount
environment.filters["wordwrap"] = filters.wordwrap
environment.filters["center"] = filters.center
environment.filters["join"] = filters.join
environment.filters["length"] = filters.length
environment.filters["random"] = filters.random
environment.filters["default"] = filters.default
environment.filters["filesizeformat"] = filters.filesizeformat
environment.filters["pprint"] = filters.pprint
django-jinja-2.1.2/django_jinja/builtins/filters.py 0000644 0001750 0000144 00000006656 12520361627 022505 0 ustar niwi users 0000000 0000000 # -*- coding: utf-8 -*-
try:
from django.utils.encoding import force_text
except ImportError:
from django.utils.encoding import force_unicode as force_text
from django.core.urlresolvers import reverse as django_reverse
from django.contrib.staticfiles.storage import staticfiles_storage
from jinja2 import Markup
def reverse(value, *args, **kwargs):
"""
Shortcut filter for reverse url on templates. Is a alternative to
django {% url %} tag, but more simple.
Usage example:
{{ 'web:timeline'|reverse(userid=2) }}
This is a equivalent to django:
{% url 'web:timeline' userid=2 %}
"""
return django_reverse(value, args=args, kwargs=kwargs)
def static(path):
return staticfiles_storage.url(path)
from django.template.defaultfilters import addslashes
from django.template.defaultfilters import capfirst
from django.utils.html import escapejs as escapejs_filter
# from django.utils.html import fix_ampersands as fix_ampersands_filter
from django.template.defaultfilters import floatformat
from django.template.defaultfilters import iriencode
from django.template.defaultfilters import linenumbers
from django.template.defaultfilters import make_list
from django.template.defaultfilters import stringformat
from django.template.defaultfilters import title
from django.template.defaultfilters import truncatechars
from django.template.defaultfilters import truncatewords
from django.template.defaultfilters import truncatewords_html
from django.template.defaultfilters import upper
from django.template.defaultfilters import lower
from django.template.defaultfilters import urlencode
from django.template.defaultfilters import urlize
from django.template.defaultfilters import urlizetrunc
from django.template.defaultfilters import wordcount
from django.template.defaultfilters import wordwrap
from django.template.defaultfilters import ljust
from django.template.defaultfilters import rjust
from django.template.defaultfilters import center
from django.template.defaultfilters import cut
from django.template.defaultfilters import linebreaks_filter
from django.template.defaultfilters import linebreaksbr
from django.template.defaultfilters import removetags
from django.template.defaultfilters import striptags
from django.template.defaultfilters import join
from django.template.defaultfilters import length
from django.template.defaultfilters import random
from django.template.defaultfilters import add
from django.template.defaultfilters import date
from django.template.defaultfilters import time
from django.template.defaultfilters import timesince_filter
from django.template.defaultfilters import timeuntil_filter
from django.template.defaultfilters import default
from django.template.defaultfilters import default_if_none
from django.template.defaultfilters import divisibleby
from django.template.defaultfilters import yesno
from django.template.defaultfilters import filesizeformat
from django.template.defaultfilters import pprint
from django.template.defaultfilters import pluralize
try:
from django.utils.text import slugify as djslugify
except ImportError:
from django.template.defaultfilters import slugify as djslugify
def slugify(value):
return djslugify(force_text(value))
from functools import partial
linebreaksbr = partial(linebreaksbr, autoescape=True)
# TZ
from django.templatetags.tz import do_timezone as timezone
from django.templatetags.tz import localtime
from django.templatetags.tz import utc
django-jinja-2.1.2/django_jinja/contrib/ 0000755 0001750 0000144 00000000000 12653222617 020257 5 ustar niwi users 0000000 0000000 django-jinja-2.1.2/django_jinja/contrib/_easy_thumbnails/ 0000755 0001750 0000144 00000000000 12653222617 023605 5 ustar niwi users 0000000 0000000 django-jinja-2.1.2/django_jinja/contrib/_easy_thumbnails/templatetags/ 0000755 0001750 0000144 00000000000 12653222617 026277 5 ustar niwi users 0000000 0000000 django-jinja-2.1.2/django_jinja/contrib/_easy_thumbnails/templatetags/__init__.py 0000644 0001750 0000144 00000000032 12520361627 030401 0 ustar niwi users 0000000 0000000 # -*- coding: utf-8 -*-
django-jinja-2.1.2/django_jinja/contrib/_easy_thumbnails/templatetags/thumbnails.py 0000644 0001750 0000144 00000002326 12520361627 031020 0 ustar niwi users 0000000 0000000 # -*- coding: utf-8 -*-
import logging
from easy_thumbnails.conf import settings
from easy_thumbnails.templatetags import thumbnail as _thumbnail
from django_jinja import library
from functools import wraps
logger = logging.getLogger(__name__)
def debug_silence(error_output=''):
def inner(fn):
@wraps(fn)
def wrapper(*args, **kwargs):
try:
return fn(*args, **kwargs)
except Exception as exc:
if settings.THUMBNAIL_DEBUG:
raise
logger.error('Error: %s', exc)
return error_output
return wrapper
return inner
@library.filter
@debug_silence(error_output='')
def thumbnail_url(source, alias):
return _thumbnail.thumbnail_url(source, alias)
@library.global_function
@debug_silence(error_output=None)
def thumbnailer_passive(obj):
return _thumbnail.thumbnailer_passive(obj)
@library.global_function
@debug_silence(error_output=None)
def thumbnailer(obj):
return _thumbnail.thumbnailer(obj)
@library.global_function
@debug_silence(error_output='')
def thumbnail(source, **kwargs):
thumbnail = _thumbnail.get_thumbnailer(source).get_thumbnail(kwargs)
return thumbnail.url
django-jinja-2.1.2/django_jinja/contrib/_easy_thumbnails/__init__.py 0000644 0001750 0000144 00000000032 12520361627 025707 0 ustar niwi users 0000000 0000000 # -*- coding: utf-8 -*-
django-jinja-2.1.2/django_jinja/contrib/_easy_thumbnails/models.py 0000644 0001750 0000144 00000000032 12520361627 025433 0 ustar niwi users 0000000 0000000 # -*- coding: utf-8 -*-
django-jinja-2.1.2/django_jinja/contrib/_humanize/ 0000755 0001750 0000144 00000000000 12653222617 022236 5 ustar niwi users 0000000 0000000 django-jinja-2.1.2/django_jinja/contrib/_humanize/templatetags/ 0000755 0001750 0000144 00000000000 12653222617 024730 5 ustar niwi users 0000000 0000000 django-jinja-2.1.2/django_jinja/contrib/_humanize/templatetags/__init__.py 0000644 0001750 0000144 00000000032 12520361627 027032 0 ustar niwi users 0000000 0000000 # -*- coding: utf-8 -*-
django-jinja-2.1.2/django_jinja/contrib/_humanize/templatetags/_humanize.py 0000644 0001750 0000144 00000001160 12520361627 027255 0 ustar niwi users 0000000 0000000 # -*- coding: utf-8 -*-
from django.contrib.humanize.templatetags import humanize
from django_jinja import library
@library.filter
def ordinal(source):
return humanize.ordinal(source)
@library.filter
def intcomma(source, use_l10n=True):
return humanize.intcomma(source, use_l10n)
@library.filter
def intword(source):
return humanize.intword(source)
@library.filter
def apnumber(source):
return humanize.apnumber(source)
@library.filter
def naturalday(source, arg=None):
return humanize.naturalday(source, arg)
@library.filter
def naturaltime(source):
return humanize.naturaltime(source)
django-jinja-2.1.2/django_jinja/contrib/_humanize/__init__.py 0000644 0001750 0000144 00000000032 12520361627 024340 0 ustar niwi users 0000000 0000000 # -*- coding: utf-8 -*-
django-jinja-2.1.2/django_jinja/contrib/_humanize/models.py 0000644 0001750 0000144 00000000032 12520361627 024064 0 ustar niwi users 0000000 0000000 # -*- coding: utf-8 -*-
django-jinja-2.1.2/django_jinja/contrib/_pipeline/ 0000755 0001750 0000144 00000000000 12653222617 022223 5 ustar niwi users 0000000 0000000 django-jinja-2.1.2/django_jinja/contrib/_pipeline/templates/ 0000755 0001750 0000144 00000000000 12653222617 024221 5 ustar niwi users 0000000 0000000 django-jinja-2.1.2/django_jinja/contrib/_pipeline/templates/pipeline/ 0000755 0001750 0000144 00000000000 12653222617 026026 5 ustar niwi users 0000000 0000000 django-jinja-2.1.2/django_jinja/contrib/_pipeline/templates/pipeline/css.jinja 0000644 0001750 0000144 00000000235 12520361627 027631 0 ustar niwi users 0000000 0000000
django-jinja-2.1.2/django_jinja/contrib/_pipeline/templates/pipeline/inline_js.jinja 0000644 0001750 0000144 00000000214 12520361627 031010 0 ustar niwi users 0000000 0000000
django-jinja-2.1.2/django_jinja/contrib/_pipeline/templates/pipeline/js.jinja 0000644 0001750 0000144 00000000202 12520361627 027447 0 ustar niwi users 0000000 0000000
django-jinja-2.1.2/django_jinja/contrib/_pipeline/templatetags/ 0000755 0001750 0000144 00000000000 12653222617 024715 5 ustar niwi users 0000000 0000000 django-jinja-2.1.2/django_jinja/contrib/_pipeline/templatetags/__init__.py 0000644 0001750 0000144 00000000032 12520361627 027017 0 ustar niwi users 0000000 0000000 # -*- coding: utf-8 -*-
django-jinja-2.1.2/django_jinja/contrib/_pipeline/templatetags/_pipeline.py 0000644 0001750 0000144 00000005452 12520361627 027237 0 ustar niwi users 0000000 0000000 # -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import
import jinja2
from django.contrib.staticfiles.storage import staticfiles_storage
from django.template.loader import render_to_string
from pipeline.conf import settings
from pipeline.utils import guess_type
from pipeline.packager import Packager, PackageNotFound
from pipeline.collector import default_collector
from django_jinja import library, utils
@library.global_function
@jinja2.contextfunction
@utils.safe
def compressed_css(ctx, name):
package = settings.PIPELINE_CSS.get(name, {})
if package:
package = {name: package}
packager = Packager(css_packages=package, js_packages={})
try:
package = packager.package_for('css', name)
except PackageNotFound:
return ""
def _render_css(path):
template_name = package.template_name or "pipeline/css.jinja"
context = package.extra_context
context.update({
'type': guess_type(path, 'text/css'),
'url': staticfiles_storage.url(path)
})
template = ctx.environment.get_template(template_name)
return template.render(context)
if settings.PIPELINE_ENABLED:
return _render_css(package.output_filename)
else:
default_collector.collect()
paths = packager.compile(package.paths)
tags = [_render_css(path) for path in paths]
return '\n'.join(tags)
@library.global_function
@jinja2.contextfunction
@utils.safe
def compressed_js(ctx, name):
package = settings.PIPELINE_JS.get(name, {})
if package:
package = {name: package}
packager = Packager(css_packages={}, js_packages=package)
try:
package = packager.package_for("js", name)
except PackageNotFound:
return ""
def _render_js(path):
template_name = package.template_name or "pipeline/js.jinja"
context = package.extra_context
context.update({
'type': guess_type(path, 'text/javascript'),
'url': staticfiles_storage.url(path),
})
template = ctx.environment.get_template(template_name)
return template.render(context)
def _render_inline_js(js):
context = package.extra_context
context.update({
'source': js
})
template = ctx.environment.get_template("pipeline/inline_js.jinja")
return template.render(context)
# Render a optimized one
if settings.PIPELINE_ENABLED:
return _render_js(package.output_filename)
else:
default_collector.collect()
paths = packager.compile(package.paths)
templates = packager.pack_templates(package)
tags = [_render_js(js) for js in paths]
if templates:
tags.append(_render_inline_js(templates))
return '\n'.join(tags)
django-jinja-2.1.2/django_jinja/contrib/_pipeline/__init__.py 0000644 0001750 0000144 00000000030 12520361627 024323 0 ustar niwi users 0000000 0000000 # -*- coding: utf-8 -*-
django-jinja-2.1.2/django_jinja/contrib/_pipeline/models.py 0000644 0001750 0000144 00000000000 12520361627 024044 0 ustar niwi users 0000000 0000000 django-jinja-2.1.2/django_jinja/contrib/_subdomains/ 0000755 0001750 0000144 00000000000 12653222617 022562 5 ustar niwi users 0000000 0000000 django-jinja-2.1.2/django_jinja/contrib/_subdomains/templatetags/ 0000755 0001750 0000144 00000000000 12653222617 025254 5 ustar niwi users 0000000 0000000 django-jinja-2.1.2/django_jinja/contrib/_subdomains/templatetags/__init__.py 0000644 0001750 0000144 00000000000 12520361627 027351 0 ustar niwi users 0000000 0000000 django-jinja-2.1.2/django_jinja/contrib/_subdomains/templatetags/subdomainurls.py 0000644 0001750 0000144 00000000446 12520361627 030517 0 ustar niwi users 0000000 0000000 # -*- coding: utf-8 -*-
from django_jinja import library
from jinja2 import contextfunction
from subdomains.templatetags.subdomainurls import url as subdomain_url
@library.global_function
@contextfunction
def url(context, *args, **kwargs):
return subdomain_url(context, *args, **kwargs)
django-jinja-2.1.2/django_jinja/contrib/_subdomains/__init__.py 0000644 0001750 0000144 00000000000 12520361627 024657 0 ustar niwi users 0000000 0000000 django-jinja-2.1.2/django_jinja/contrib/_subdomains/models.py 0000644 0001750 0000144 00000000000 12520361627 024403 0 ustar niwi users 0000000 0000000 django-jinja-2.1.2/django_jinja/contrib/__init__.py 0000644 0001750 0000144 00000000000 12520361627 022354 0 ustar niwi users 0000000 0000000 django-jinja-2.1.2/django_jinja/management/ 0000755 0001750 0000144 00000000000 12653222617 020733 5 ustar niwi users 0000000 0000000 django-jinja-2.1.2/django_jinja/management/commands/ 0000755 0001750 0000144 00000000000 12653222617 022534 5 ustar niwi users 0000000 0000000 django-jinja-2.1.2/django_jinja/management/commands/__init__.py 0000644 0001750 0000144 00000000000 12520361627 024631 0 ustar niwi users 0000000 0000000 django-jinja-2.1.2/django_jinja/management/commands/makemessages.py 0000644 0001750 0000144 00000005760 12635323122 025554 0 ustar niwi users 0000000 0000000 """Jinja2's i18n functionality is not exactly the same as Django's.
In particular, the tags names and their syntax are different:
1. The Django ``trans`` tag is replaced by a _() global.
2. The Django ``blocktrans`` tag is called ``trans``.
(1) isn't an issue, since the whole ``makemessages`` process is based on
converting the template tags to ``_()`` calls. However, (2) means that
those Jinja2 ``trans`` tags will not be picked up my Django's
``makemessage`` command.
There aren't any nice solutions here. While Jinja2's i18n extension does
come with extraction capabilities built in, the code behind ``makemessages``
unfortunately isn't extensible, so we can:
* Duplicate the command + code behind it.
* Offer a separate command for Jinja2 extraction.
* Try to get Django to offer hooks into makemessages().
* Monkey-patch.
We are currently doing that last thing. It turns out there we are lucky
for once: It's simply a matter of extending two regular expressions.
Credit for the approach goes to:
http://stackoverflow.com/questions/2090717/getting-translation-strings-for-jinja2-templates-integrated-with-django-1-x
"""
import re
from django.core.management.commands import makemessages
from django.utils.translation import trans_real
from django.template.base import BLOCK_TAG_START, BLOCK_TAG_END
strip_whitespace_right = re.compile(r"(%s-?\s*(trans|pluralize).*?-%s)\s+" % (BLOCK_TAG_START, BLOCK_TAG_END), re.U)
strip_whitespace_left = re.compile(r"\s+(%s-\s*(endtrans|pluralize).*?-?%s)" % (BLOCK_TAG_START, BLOCK_TAG_END), re.U)
def strip_whitespaces(src):
src = strip_whitespace_left.sub(r'\1', src)
src = strip_whitespace_right.sub(r'\1', src)
return src
class Command(makemessages.Command):
def handle(self, *args, **options):
old_endblock_re = trans_real.endblock_re
old_block_re = trans_real.block_re
old_constant_re = trans_real.constant_re
old_templatize = trans_real.templatize
# Extend the regular expressions that are used to detect
# translation blocks with an "OR jinja-syntax" clause.
trans_real.endblock_re = re.compile(
trans_real.endblock_re.pattern + '|' + r"""^-?\s*endtrans\s*-?$""")
trans_real.block_re = re.compile(
trans_real.block_re.pattern + '|' + r"""^-?\s*trans(?:\s+(?!'|")(?=.*?=.*?)|\s*-?$)""")
trans_real.plural_re = re.compile(
trans_real.plural_re.pattern + '|' + r"""^-?\s*pluralize(?:\s+.+|-?$)""")
trans_real.constant_re = re.compile(r"""_\(((?:".*?")|(?:'.*?')).*\)""")
def my_templatize(src, origin=None):
new_src = strip_whitespaces(src)
return old_templatize(new_src, origin)
trans_real.templatize = my_templatize
try:
super(Command, self).handle(*args, **options)
finally:
trans_real.endblock_re = old_endblock_re
trans_real.block_re = old_block_re
trans_real.templatize = old_templatize
trans_real.constant_re = old_constant_re
django-jinja-2.1.2/django_jinja/management/__init__.py 0000644 0001750 0000144 00000000000 12520361627 023030 0 ustar niwi users 0000000 0000000 django-jinja-2.1.2/django_jinja/views/ 0000755 0001750 0000144 00000000000 12653222617 017754 5 ustar niwi users 0000000 0000000 django-jinja-2.1.2/django_jinja/views/generic/ 0000755 0001750 0000144 00000000000 12653222617 021370 5 ustar niwi users 0000000 0000000 django-jinja-2.1.2/django_jinja/views/generic/__init__.py 0000644 0001750 0000144 00000001015 12520361635 023473 0 ustar niwi users 0000000 0000000 from .dates import (ArchiveIndexView, YearArchiveView, MonthArchiveView,
WeekArchiveView, DayArchiveView, TodayArchiveView,
DateDetailView)
from .detail import DetailView
from .edit import CreateView, UpdateView, DeleteView
from .list import ListView
__all__ = [
'ArchiveIndexView', 'YearArchiveView', 'MonthArchiveView',
'WeekArchiveView', 'DayArchiveView', 'TodayArchiveView',
'DateDetailView', 'DetailView', 'CreateView', 'UpdateView',
'DeleteView', 'ListView',
]
django-jinja-2.1.2/django_jinja/views/generic/base.py 0000644 0001750 0000144 00000002276 12520361635 022660 0 ustar niwi users 0000000 0000000 # -*- coding: utf-8 -*-
from ...base import get_match_extension
class Jinja2TemplateResponseMixin(object):
jinja2_template_extension = None
def get_template_names(self):
"""
Return a list of template names to be used for the request.
This calls the super class's get_template_names and appends
the Jinja2 match extension is suffixed to the returned values.
If you specify jinja2_template_extension then that value will
be used. Otherwise it tries to detect the extension based on
values in settings.
If you would like to not have it append an extension, set
jinja2_template_extension to '' (empty string).
"""
vals = super(Jinja2TemplateResponseMixin, self).get_template_names()
ext = self.jinja2_template_extension
if ext is None:
ext = get_match_extension(using=getattr(self, 'template_engine', None))
# Exit early if the user has specified an empty match extension
if not ext:
return vals
names = []
for val in vals:
if not val.endswith(ext):
val += ext
names.append(val)
return names
django-jinja-2.1.2/django_jinja/views/generic/dates.py 0000644 0001750 0000144 00000002354 12520361635 023043 0 ustar niwi users 0000000 0000000 # -*- coding: utf-8 -*-
from django.views.generic.dates import ArchiveIndexView as _django_ArchiveIndexView
from django.views.generic.dates import YearArchiveView as _django_YearArchiveView
from django.views.generic.dates import MonthArchiveView as _django_MonthArchiveView
from django.views.generic.dates import WeekArchiveView as _django_WeekArchiveView
from django.views.generic.dates import DayArchiveView as _django_DayArchiveView
from django.views.generic.dates import TodayArchiveView as _django_TodayArchiveView
from django.views.generic.dates import DateDetailView as _django_DateDetailView
from .base import Jinja2TemplateResponseMixin
class ArchiveIndexView(Jinja2TemplateResponseMixin, _django_ArchiveIndexView):
pass
class YearArchiveView(Jinja2TemplateResponseMixin, _django_YearArchiveView):
pass
class MonthArchiveView(Jinja2TemplateResponseMixin, _django_MonthArchiveView):
pass
class WeekArchiveView(Jinja2TemplateResponseMixin, _django_WeekArchiveView):
pass
class DayArchiveView(Jinja2TemplateResponseMixin, _django_DayArchiveView):
pass
class TodayArchiveView(Jinja2TemplateResponseMixin, _django_TodayArchiveView):
pass
class DateDetailView(Jinja2TemplateResponseMixin, _django_DateDetailView):
pass
django-jinja-2.1.2/django_jinja/views/generic/detail.py 0000644 0001750 0000144 00000000337 12520361635 023204 0 ustar niwi users 0000000 0000000 # -*- coding: utf-8 -*-
from django.views.generic.detail import DetailView as _django_DetailView
from .base import Jinja2TemplateResponseMixin
class DetailView(Jinja2TemplateResponseMixin, _django_DetailView):
pass
django-jinja-2.1.2/django_jinja/views/generic/edit.py 0000644 0001750 0000144 00000001005 12520361635 022660 0 ustar niwi users 0000000 0000000 # -*- coding: utf-8 -*-
from django.views.generic.edit import CreateView as _django_CreateView
from django.views.generic.edit import DeleteView as _django_DeleteView
from django.views.generic.edit import UpdateView as _django_UpdateView
from .base import Jinja2TemplateResponseMixin
class CreateView(Jinja2TemplateResponseMixin, _django_CreateView):
pass
class DeleteView(Jinja2TemplateResponseMixin, _django_DeleteView):
pass
class UpdateView(Jinja2TemplateResponseMixin, _django_UpdateView):
pass
django-jinja-2.1.2/django_jinja/views/generic/list.py 0000644 0001750 0000144 00000000325 12520361635 022712 0 ustar niwi users 0000000 0000000 # -*- coding: utf-8 -*-
from django.views.generic.list import ListView as _django_ListView
from .base import Jinja2TemplateResponseMixin
class ListView(Jinja2TemplateResponseMixin, _django_ListView):
pass
django-jinja-2.1.2/django_jinja/views/__init__.py 0000644 0001750 0000144 00000004106 12520361635 022063 0 ustar niwi users 0000000 0000000 # -*- coding: utf-8 -*-
import django
from django.conf import settings
from django.views.generic import View
from django.template import loader, RequestContext
from django import http
class GenericView(View):
response_cls = http.HttpResponse
content_type = "text/html"
tmpl_name = None
def get_context_data(self):
return {"view": self}
def get(self, request, *args, **kwargs):
context = self.get_context_data()
if django.VERSION[:2] < (1, 8):
output = loader.render_to_string(self.tmpl_name, context,
context_instance=RequestContext(request))
else:
output = loader.render_to_string(self.tmpl_name, context, request=request)
return self.response_cls(output, content_type=self.content_type)
class ErrorView(GenericView):
def head(self, request, *args, **kwargs):
return self.get(request, *args, **kwargs)
def post(self, request, *args, **kwargs):
return self.get(request, *args, **kwargs)
def options(self, request, *args, **kwargs):
return self.get(request, *args, **kwargs)
def delete(self, request, *args, **kwargs):
return self.get(request, *args, **kwargs)
def put(self, request, *args, **kwargs):
return self.get(request, *args, **kwargs)
def patch(self, request, *args, **kwargs):
return self.get(request, *args, **kwargs)
class PageNotFound(ErrorView):
tmpl_name = "404" + getattr(settings, 'DEFAULT_JINJA2_TEMPLATE_EXTENSION', '.jinja')
response_cls = http.HttpResponseNotFound
class PermissionDenied(ErrorView):
tmpl_name = "403" + getattr(settings, 'DEFAULT_JINJA2_TEMPLATE_EXTENSION', '.jinja')
response_cls = http.HttpResponseForbidden
class BadRequest(ErrorView):
tmpl_name = "400" + getattr(settings, 'DEFAULT_JINJA2_TEMPLATE_EXTENSION', '.jinja')
response_cls = http.HttpResponseBadRequest
class ServerError(ErrorView):
tmpl_name = "500" + getattr(settings, 'DEFAULT_JINJA2_TEMPLATE_EXTENSION', '.jinja')
response_cls = http.HttpResponseServerError
django-jinja-2.1.2/django_jinja/__init__.py 0000644 0001750 0000144 00000000076 12520361627 020731 0 ustar niwi users 0000000 0000000 default_app_config = 'django_jinja.apps.DjangoJinjaAppConfig'
django-jinja-2.1.2/django_jinja/apps.py 0000644 0001750 0000144 00000000365 12634224002 020125 0 ustar niwi users 0000000 0000000 import django
from django.apps import AppConfig
from django_jinja import base
class DjangoJinjaAppConfig(AppConfig):
name = "django_jinja"
verbose_name = "Django Jinja"
def ready(self):
base.patch_django_for_autoescape()
django-jinja-2.1.2/django_jinja/backend.py 0000644 0001750 0000144 00000026304 12653222065 020562 0 ustar niwi users 0000000 0000000 """
Since django 1.8.x, django comes with native multiple template engine support.
It also comes with jinja2 backend, but it is slightly unflexible, and it does
not support by default all django filters and related stuff.
This is an implementation of django backend inteface for use
django_jinja easy with django 1.8.
"""
from __future__ import absolute_import
import copy
import sys
import os
import os.path as path
from importlib import import_module
import jinja2
from django.conf import settings
from django.core import signals
from django.core.exceptions import ImproperlyConfigured
from django.dispatch import receiver
from django.middleware.csrf import get_token
from django.template import RequestContext
from django.template import TemplateDoesNotExist
from django.template import TemplateSyntaxError
from django.template.backends.base import BaseEngine
from django.template.backends.utils import csrf_input_lazy
from django.template.backends.utils import csrf_token_lazy
from django.utils import lru_cache
from django.utils import six
from django.utils.encoding import smart_text
from django.utils.functional import SimpleLazyObject
from django.utils.functional import cached_property
from django.utils.module_loading import import_string
from . import base
from . import builtins
from . import library
from . import utils
class Origin(object):
"""
A container to hold debug information as described in the template API
documentation.
"""
def __init__(self, name, template_name):
self.name = name
self.template_name = template_name
class Template(object):
def __init__(self, template, backend):
self.template = template
self.backend = backend
self._debug = False
self.origin = Origin(name=template.filename, template_name=template.name)
@property
def name(self):
return self.origin.name
def render(self, context=None, request=None):
if context is None:
context = {}
if request is not None:
def _get_val():
token = get_token(request)
if token is None:
return 'NOTPROVIDED'
else:
return smart_text(token)
context["request"] = request
context["csrf_token"] = SimpleLazyObject(_get_val)
# Support for django context processors
for processor in self.backend.context_processors:
context.update(processor(request))
if self.backend._tmpl_debug:
from django.test import signals
from django.template.context import BaseContext
# Define a "django" like context for emitatet the multi
# layered context object. This is mainly for apps like
# django-debug-toolbar that are very coupled to django's
# internal implementation of context.
if not isinstance(context, BaseContext):
class CompatibilityContext(dict):
@property
def dicts(self):
return [self]
context = CompatibilityContext(context)
signals.template_rendered.send(sender=self, template=self,
context=context)
return self.template.render(context)
class Jinja2(BaseEngine):
app_dirname = "templates"
@staticmethod
@lru_cache.lru_cache()
def get_default():
"""
When only one django-jinja backend is configured, returns it.
Raises ImproperlyConfigured otherwise.
This is required for finding the match extension where the
developer does not specify a template_engine on a
TemplateResponseMixin subclass.
"""
from django.template import engines
jinja_engines = [engine for engine in engines.all()
if isinstance(engine, Jinja2)]
if len(jinja_engines) == 1:
# Unwrap the Jinja2 engine instance.
return jinja_engines[0]
elif len(jinja_engines) == 0:
raise ImproperlyConfigured(
"No Jinja2 backend is configured.")
else:
raise ImproperlyConfigured(
"Several Jinja2 backends are configured. "
"You must select one explicitly.")
def __init__(self, params):
params = params.copy()
options = params.pop("OPTIONS", {}).copy()
self.app_dirname = options.pop("app_dirname", "templates")
super(Jinja2, self).__init__(params)
newstyle_gettext = options.pop("newstyle_gettext", True)
context_processors = options.pop("context_processors", [])
match_extension = options.pop("match_extension", ".jinja")
match_regex = options.pop("match_regex", None)
environment_clspath = options.pop("environment", "jinja2.Environment")
extra_filters = options.pop("filters", {})
extra_tests = options.pop("tests", {})
extra_globals = options.pop("globals", {})
extra_constants = options.pop("constants", {})
translation_engine = options.pop("translation_engine", "django.utils.translation")
tmpl_debug = options.pop("debug", settings.DEBUG)
bytecode_cache = options.pop("bytecode_cache", {})
bytecode_cache.setdefault("name", "default")
bytecode_cache.setdefault("enabled", False)
bytecode_cache.setdefault("backend", "django_jinja.cache.BytecodeCache")
undefined = options.pop("undefined", None)
if undefined is not None:
if isinstance(undefined, six.string_types):
options["undefined"] = utils.load_class(undefined)
else:
options["undefined"] = undefined
if settings.DEBUG:
options.setdefault("undefined", jinja2.DebugUndefined)
else:
options.setdefault("undefined", jinja2.Undefined)
environment_cls = import_string(environment_clspath)
options.setdefault("loader", jinja2.FileSystemLoader(self.template_dirs))
options.setdefault("extensions", builtins.DEFAULT_EXTENSIONS)
options.setdefault("auto_reload", settings.DEBUG)
options.setdefault("autoescape", True)
self.env = environment_cls(**options)
# Initialize i18n support
if settings.USE_I18N:
translation = import_module(translation_engine)
self.env.install_gettext_translations(translation, newstyle=newstyle_gettext)
else:
self.env.install_null_translations(newstyle=newstyle_gettext)
self._context_processors = context_processors
self._match_regex = match_regex
self._match_extension = match_extension
self._tmpl_debug = tmpl_debug
self._bytecode_cache = bytecode_cache
self._initialize_builtins(filters=extra_filters,
tests=extra_tests,
globals=extra_globals,
constants=extra_constants)
self._initialize_thirdparty()
self._initialize_bytecode_cache()
def _initialize_bytecode_cache(self):
if self._bytecode_cache["enabled"]:
cls = utils.load_class(self._bytecode_cache["backend"])
self.env.bytecode_cache = cls(self._bytecode_cache["name"])
def _initialize_thirdparty(self):
"""
Iterate over all available apps in searching and preloading
available template filters or functions for jinja2.
"""
for app_path, mod_path in base._iter_templatetags_modules_list():
if not path.isdir(mod_path):
continue
for filename in filter(lambda x: x.endswith(".py") or x.endswith(".pyc"), os.listdir(mod_path)):
# Exclude __init__.py files
if filename == "__init__.py" or filename == "__init__.pyc":
continue
file_mod_path = "%s.templatetags.%s" % (app_path, filename.rsplit(".", 1)[0])
try:
import_module(file_mod_path)
except ImportError:
pass
library._update_env(self.env)
def _initialize_builtins(self, filters=None, tests=None, globals=None, constants=None):
def insert(data, name, value):
if isinstance(value, six.string_types):
data[name] = import_string(value)
else:
data[name] = value
if filters:
for name, value in filters.items():
insert(self.env.filters, name, value)
if tests:
for name, value in tests.items():
insert(self.env.tests, name, value)
if globals:
for name, value in globals.items():
insert(self.env.globals, name, value)
if constants:
for name, value in constants.items():
self.env.globals[name] = value
@cached_property
def context_processors(self):
return tuple(import_string(path) for path in self._context_processors)
@property
def match_extension(self):
return self._match_extension
def from_string(self, template_code):
return Template(self.env.from_string(template_code), self)
def match_template(self, template_name):
return base.match_template(template_name,
self._match_extension,
self._match_regex)
def get_template(self, template_name):
if not self.match_template(template_name):
message = "Template {} does not exists".format(template_name)
raise TemplateDoesNotExist(message)
try:
return Template(self.env.get_template(template_name), self)
except jinja2.TemplateNotFound as exc:
if utils.DJANGO_18:
exc = TemplateDoesNotExist(exc.name)
else:
exc = TemplateDoesNotExist(exc.name, backend=self)
six.reraise(
TemplateDoesNotExist,
exc,
sys.exc_info()[2],
)
except jinja2.TemplateSyntaxError as exc:
new = TemplateSyntaxError(exc.args)
new.template_debug = get_exception_info(exc)
six.reraise(TemplateSyntaxError, new, sys.exc_info()[2])
@receiver(signals.setting_changed)
def _setting_changed(sender, setting, *args, **kwargs):
""" Reset the Jinja2.get_default() cached when TEMPLATES changes. """
if setting == "TEMPLATES":
Jinja2.get_default.cache_clear()
def get_exception_info(exception):
"""
Formats exception information for display on the debug page using the
structure described in the template API documentation.
"""
context_lines = 10
lineno = exception.lineno
lines = list(enumerate(exception.source.strip().split("\n"), start=1))
during = lines[lineno - 1][1]
total = len(lines)
top = max(0, lineno - context_lines - 1)
bottom = min(total, lineno + context_lines)
return {
'name': exception.filename,
'message': exception.message,
'source_lines': lines[top:bottom],
'line': lineno,
'before': '',
'during': during,
'after': '',
'total': total,
'top': top,
'bottom': bottom,
}
django-jinja-2.1.2/django_jinja/base.py 0000644 0001750 0000144 00000006705 12634224002 020100 0 ustar niwi users 0000000 0000000 # -*- coding: utf-8 -*-
import re
import os
import os.path as path
from importlib import import_module
import django
from django.conf import settings
from django.template.context import BaseContext
from django.utils import six
def dict_from_context(context):
"""
Converts context to native python dict.
"""
if isinstance(context, BaseContext):
new_dict = {}
for i in reversed(list(context)):
new_dict.update(dict_from_context(i))
return new_dict
return dict(context)
def _iter_templatetags_modules_list():
"""
Get list of modules that contains templatetags
submodule.
"""
from django.apps import apps
all_modules = [x.name for x in apps.get_app_configs()]
for app_path in all_modules:
try:
mod = import_module(app_path + ".templatetags")
# Empty folders can lead to unexpected behavior with Python 3.
# We make sure to have the `__file__` attribute.
if hasattr(mod, '__file__'):
yield (app_path, path.dirname(mod.__file__))
except ImportError:
pass
def patch_django_for_autoescape():
"""
Patch django modules for make them compatible with
jinja autoescape implementation.
"""
from django.utils import safestring
from django.forms.forms import BoundField
from django.forms.utils import ErrorList
from django.forms.utils import ErrorDict
if hasattr(safestring, "SafeText"):
if not hasattr(safestring.SafeText, "__html__"):
safestring.SafeText.__html__ = lambda self: six.text_type(self)
if hasattr(safestring, "SafeString"):
if not hasattr(safestring.SafeString, "__html__"):
safestring.SafeString.__html__ = lambda self: six.text_type(self)
if hasattr(safestring, "SafeUnicode"):
if not hasattr(safestring.SafeUnicode, "__html__"):
safestring.SafeUnicode.__html__ = lambda self: six.text_type(self)
if hasattr(safestring, "SafeBytes"):
if not hasattr(safestring.SafeBytes, "__html__"):
safestring.SafeBytes.__html__ = lambda self: six.text_type(self)
if not hasattr(BoundField, "__html__"):
BoundField.__html__ = lambda self: six.text_type(self)
if not hasattr(ErrorList, "__html__"):
ErrorList.__html__ = lambda self: six.text_type(self)
if not hasattr(ErrorDict, "__html__"):
ErrorDict.__html__ = lambda self: six.text_type(self)
def get_match_extension(using=None):
"""
Gets the extension that the template loader will match for
django-jinja. This returns Jinja2.match_extension.
The "using" parameter selects with Jinja2 backend to use if
you have multiple ones configured in settings.TEMPLATES.
If it is None and only one Jinja2 backend is defined then it
will use that, otherwise an ImproperlyConfigured exception
is thrown.
"""
from .backend import Jinja2
from django.template import engines
if using is None:
engine = Jinja2.get_default()
else:
engine = engines[using]
return engine.match_extension
def match_template(template_name, extension, regex):
if extension:
matches_extension = template_name.endswith(extension)
if regex:
return matches_extension and re.match(regex, template_name)
else:
return template_name.endswith(extension)
elif regex:
return re.match(regex, template_name)
else:
return True
django-jinja-2.1.2/django_jinja/cache.py 0000644 0001750 0000144 00000001446 12653222065 020236 0 ustar niwi users 0000000 0000000 # -*- coding: utf-8 -*-
import django
from django.utils.functional import cached_property
from jinja2 import BytecodeCache as _BytecodeCache
class BytecodeCache(_BytecodeCache):
"""
A bytecode cache for Jinja2 that uses Django's caching framework.
"""
def __init__(self, cache_name):
self._cache_name = cache_name
@cached_property
def backend(self):
from django.core.cache import caches
return caches[self._cache_name]
def load_bytecode(self, bucket):
key = 'jinja2_%s' % str(bucket.key)
bytecode = self.backend.get(key)
if bytecode:
bucket.bytecode_from_string(bytecode)
def dump_bytecode(self, bucket):
key = 'jinja2_%s' % str(bucket.key)
self.backend.set(key, bucket.bytecode_to_string())
django-jinja-2.1.2/django_jinja/library.py 0000644 0001750 0000144 00000004312 12634216425 020634 0 ustar niwi users 0000000 0000000 import functools
import warnings
from django.template.loader import render_to_string
from django.utils.safestring import mark_safe
# Global register dict for third party
# template functions, filters and extensions.
_local_env = {
"globals": {},
"tests": {},
"filters": {},
"extensions": set([]),
}
def _update_env(env):
"""
Given a jinja environment, update it with third party
collected environment extensions.
"""
env.globals.update(_local_env["globals"])
env.tests.update(_local_env["tests"])
env.filters.update(_local_env["filters"])
for extension in _local_env["extensions"]:
env.add_extension(extension)
def _attach_function(attr, func, name=None):
if name is None:
name = func.__name__
global _local_env
_local_env[attr][name] = func
return func
def _register_function(attr, name=None, fn=None):
if name is None and fn is None:
def dec(func):
return _attach_function(attr, func)
return dec
elif name is not None and fn is None:
if callable(name):
return _attach_function(attr, name)
else:
def dec(func):
return _register_function(attr, name, func)
return dec
elif name is not None and fn is not None:
return _attach_function(attr, fn, name)
raise RuntimeError("Invalid parameters")
def extension(extension):
global _local_env
_local_env["extensions"].add(extension)
return extension
def global_function(*args, **kwargs):
return _register_function("globals", *args, **kwargs)
def test(*args, **kwargs):
return _register_function("tests", *args, **kwargs)
def filter(*args, **kwargs):
return _register_function("filters", *args, **kwargs)
def render_with(template, fn=None):
"""
Makes simple function works like
django's default inclusion_tag: render
specified template with context returned
by decorated function.
"""
if fn is None:
return functools.partial(render_with, template)
@functools.wraps(fn)
def _wrapper(*args, **kwargs):
data = render_to_string(template, fn(*args, **kwargs))
return mark_safe(data)
return _wrapper
django-jinja-2.1.2/django_jinja/loaders.py 0000644 0001750 0000144 00000002533 12520361635 020622 0 ustar niwi users 0000000 0000000 """
Api for django <= 1.7.x that uses loader extending
way for get it working.
"""
import re
import jinja2
from django.conf import settings
from django.template import TemplateDoesNotExist
from django.template.loaders import app_directories
from django.template.loaders import filesystem
from . import base
if hasattr(settings, "DEFAULT_JINJA2_TEMPLATE_INTERCEPT_RE"):
INTERCEPT_RE = getattr(settings, "DEFAULT_JINJA2_TEMPLATE_INTERCEPT_RE")
REGEX = re.compile(INTERCEPT_RE)
EXTENSION = None
else:
REGEX = None
EXTENSION = getattr(settings, 'DEFAULT_JINJA2_TEMPLATE_EXTENSION', '.jinja')
class LoaderMixin(object):
is_usable = True
def match_template(self, template_name):
return base.match_template(template_name, regex=REGEX, extension=EXTENSION)
def load_template(self, template_name, template_dirs=None):
if self.match_template(template_name):
try:
template = base.env.get_template(template_name)
return template, template.filename
except jinja2.TemplateNotFound:
raise TemplateDoesNotExist(template_name)
else:
return super(LoaderMixin, self).load_template(template_name, template_dirs)
class FileSystemLoader(LoaderMixin, filesystem.Loader):
pass
class AppLoader(LoaderMixin, app_directories.Loader):
pass
django-jinja-2.1.2/django_jinja/models.py 0000644 0001750 0000144 00000000000 12520361627 020440 0 ustar niwi users 0000000 0000000 django-jinja-2.1.2/django_jinja/utils.py 0000644 0001750 0000144 00000001575 12653222065 020336 0 ustar niwi users 0000000 0000000 # -*- coding: utf-8 -*-
import functools
from importlib import import_module
import django
from django.utils.safestring import mark_safe
from django.core.exceptions import ImproperlyConfigured
DJANGO_18 = (django.VERSION[:2] == (1, 8))
def load_class(path):
"""
Load class from path.
"""
try:
mod_name, klass_name = path.rsplit('.', 1)
mod = import_module(mod_name)
except AttributeError as e:
raise ImproperlyConfigured('Error importing {0}: "{1}"'.format(mod_name, e))
try:
klass = getattr(mod, klass_name)
except AttributeError:
raise ImproperlyConfigured('Module "{0}" does not define a "{1}" class'.format(mod_name, klass_name))
return klass
def safe(function):
@functools.wraps(function)
def _decorator(*args, **kwargs):
return mark_safe(function(*args, **kwargs))
return _decorator
django-jinja-2.1.2/django_jinja.egg-info/ 0000755 0001750 0000144 00000000000 12653222617 020311 5 ustar niwi users 0000000 0000000 django-jinja-2.1.2/django_jinja.egg-info/PKG-INFO 0000644 0001750 0000144 00000001522 12653222617 021406 0 ustar niwi users 0000000 0000000 Metadata-Version: 1.1
Name: django-jinja
Version: 2.1.2
Summary: Jinja2 templating language integrated in Django.
Home-page: https://github.com/niwinz/django-jinja
Author: Andrey Antukh
Author-email: niwi@niwi.be
License: BSD
Description: UNKNOWN
Keywords: django,jinja2
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Framework :: Django
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Topic :: Internet :: WWW/HTTP
django-jinja-2.1.2/django_jinja.egg-info/SOURCES.txt 0000644 0001750 0000144 00000003640 12653222617 022200 0 ustar niwi users 0000000 0000000 LICENSE
MANIFEST.in
README.rst
setup.py
django_jinja/__init__.py
django_jinja/apps.py
django_jinja/backend.py
django_jinja/base.py
django_jinja/cache.py
django_jinja/library.py
django_jinja/loaders.py
django_jinja/models.py
django_jinja/utils.py
django_jinja.egg-info/PKG-INFO
django_jinja.egg-info/SOURCES.txt
django_jinja.egg-info/dependency_links.txt
django_jinja.egg-info/requires.txt
django_jinja.egg-info/top_level.txt
django_jinja/builtins/__init__.py
django_jinja/builtins/extensions.py
django_jinja/builtins/filters.py
django_jinja/contrib/__init__.py
django_jinja/contrib/_easy_thumbnails/__init__.py
django_jinja/contrib/_easy_thumbnails/models.py
django_jinja/contrib/_easy_thumbnails/templatetags/__init__.py
django_jinja/contrib/_easy_thumbnails/templatetags/thumbnails.py
django_jinja/contrib/_humanize/__init__.py
django_jinja/contrib/_humanize/models.py
django_jinja/contrib/_humanize/templatetags/__init__.py
django_jinja/contrib/_humanize/templatetags/_humanize.py
django_jinja/contrib/_pipeline/__init__.py
django_jinja/contrib/_pipeline/models.py
django_jinja/contrib/_pipeline/templates/pipeline/css.jinja
django_jinja/contrib/_pipeline/templates/pipeline/inline_js.jinja
django_jinja/contrib/_pipeline/templates/pipeline/js.jinja
django_jinja/contrib/_pipeline/templatetags/__init__.py
django_jinja/contrib/_pipeline/templatetags/_pipeline.py
django_jinja/contrib/_subdomains/__init__.py
django_jinja/contrib/_subdomains/models.py
django_jinja/contrib/_subdomains/templatetags/__init__.py
django_jinja/contrib/_subdomains/templatetags/subdomainurls.py
django_jinja/management/__init__.py
django_jinja/management/commands/__init__.py
django_jinja/management/commands/makemessages.py
django_jinja/views/__init__.py
django_jinja/views/generic/__init__.py
django_jinja/views/generic/base.py
django_jinja/views/generic/dates.py
django_jinja/views/generic/detail.py
django_jinja/views/generic/edit.py
django_jinja/views/generic/list.py django-jinja-2.1.2/django_jinja.egg-info/dependency_links.txt 0000644 0001750 0000144 00000000001 12653222617 024357 0 ustar niwi users 0000000 0000000
django-jinja-2.1.2/django_jinja.egg-info/requires.txt 0000644 0001750 0000144 00000000032 12653222617 022704 0 ustar niwi users 0000000 0000000 jinja2 >=2.5
django >=1.8
django-jinja-2.1.2/django_jinja.egg-info/top_level.txt 0000644 0001750 0000144 00000000015 12653222617 023037 0 ustar niwi users 0000000 0000000 django_jinja
django-jinja-2.1.2/LICENSE 0000644 0001750 0000144 00000002722 12520361627 015210 0 ustar niwi users 0000000 0000000 Copyright (c) 2012-2013 Andrey Antukh
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of copyright holders nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
django-jinja-2.1.2/MANIFEST.in 0000644 0001750 0000144 00000000135 12520361627 015735 0 ustar niwi users 0000000 0000000 include LICENSE README.rst
include django_jinja/contrib/_pipeline/templates/pipeline/*.jinja
django-jinja-2.1.2/README.rst 0000644 0001750 0000144 00000001261 12653222065 015666 0 ustar niwi users 0000000 0000000 django-jinja
============
Simple and nonobstructive jinja2 integration with Django.
**Now with support for django 1.8**
.. image:: https://img.shields.io/travis/niwinz/django-jinja.svg?style=flat
:target: https://travis-ci.org/niwinz/django-jinja
.. image:: https://img.shields.io/pypi/v/django-jinja.svg?style=flat
:target: https://pypi.python.org/pypi/django-jinja
.. image:: https://img.shields.io/pypi/dm/django-jinja.svg?style=flat
:target: https://pypi.python.org/pypi/django-jinja
**Documentation:** http://niwinz.github.io/django-jinja/latest/
How to install?
---------------
You can install it with pip:
.. code-block:: shell
pip install django-jinja
django-jinja-2.1.2/setup.py 0000644 0001750 0000144 00000003531 12653222337 015715 0 ustar niwi users 0000000 0000000 #!/usr/bin/env python
# -*- coding: utf-8 -*-
from setuptools import setup
import sys
INSTALL_REQUIRES = [
"jinja2 >=2.5",
"django >=1.8",
]
if sys.version_info < (2, 7):
INSTALL_REQUIRES.append("importlib")
setup(
name = "django-jinja",
version = "2.1.2",
description = "Jinja2 templating language integrated in Django.",
long_description = "",
keywords = "django, jinja2",
author = "Andrey Antukh",
author_email = "niwi@niwi.be",
url = "https://github.com/niwinz/django-jinja",
license = "BSD",
packages = [
"django_jinja",
"django_jinja.builtins",
"django_jinja.management",
"django_jinja.management.commands",
"django_jinja.contrib",
"django_jinja.contrib._pipeline",
"django_jinja.contrib._pipeline.templatetags",
"django_jinja.contrib._easy_thumbnails",
"django_jinja.contrib._easy_thumbnails.templatetags",
"django_jinja.contrib._humanize",
"django_jinja.contrib._humanize.templatetags",
"django_jinja.contrib._subdomains",
"django_jinja.contrib._subdomains.templatetags",
"django_jinja.views",
"django_jinja.views.generic",
],
install_requires = INSTALL_REQUIRES,
tests_require = [
"pytz",
],
classifiers = [
"Development Status :: 5 - Production/Stable",
"Framework :: Django",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Topic :: Internet :: WWW/HTTP",
]
)
django-jinja-2.1.2/PKG-INFO 0000644 0001750 0000144 00000001522 12653222617 015277 0 ustar niwi users 0000000 0000000 Metadata-Version: 1.1
Name: django-jinja
Version: 2.1.2
Summary: Jinja2 templating language integrated in Django.
Home-page: https://github.com/niwinz/django-jinja
Author: Andrey Antukh
Author-email: niwi@niwi.be
License: BSD
Description: UNKNOWN
Keywords: django,jinja2
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Framework :: Django
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Topic :: Internet :: WWW/HTTP
django-jinja-2.1.2/setup.cfg 0000644 0001750 0000144 00000000073 12653222617 016023 0 ustar niwi users 0000000 0000000 [egg_info]
tag_svn_revision = 0
tag_build =
tag_date = 0