2016-04-21 08:48:33 +02:00
|
|
|
from __future__ import absolute_import # Python 2 only
|
|
|
|
|
2016-08-08 11:09:23 +02:00
|
|
|
from typing import Any
|
|
|
|
|
2016-04-21 08:48:33 +02:00
|
|
|
from django.contrib.staticfiles.storage import staticfiles_storage
|
|
|
|
from django.template.defaultfilters import slugify, pluralize
|
|
|
|
from django.core.urlresolvers import reverse
|
|
|
|
from django.template.loader import render_to_string
|
|
|
|
from django.utils import translation
|
|
|
|
from django.http import HttpResponse
|
|
|
|
from jinja2 import Environment
|
|
|
|
|
2016-07-04 09:33:57 +02:00
|
|
|
from .compressors import minified_js
|
2016-05-11 19:01:53 +02:00
|
|
|
from zerver.templatetags.app_filters import display_list, render_markdown_path
|
2016-04-21 08:48:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
def render_to_response(*args, **kwargs):
|
2016-08-08 11:09:23 +02:00
|
|
|
# type: (*Any, **Any) -> HttpResponse
|
2016-04-21 08:48:33 +02:00
|
|
|
response = render_to_string(*args, **kwargs)
|
|
|
|
return HttpResponse(response)
|
|
|
|
|
|
|
|
|
|
|
|
def environment(**options):
|
2016-08-08 11:09:23 +02:00
|
|
|
# type: (**Any) -> Environment
|
2016-04-21 08:48:33 +02:00
|
|
|
env = Environment(**options)
|
|
|
|
env.globals.update({
|
|
|
|
'static': staticfiles_storage.url,
|
|
|
|
'url': reverse,
|
|
|
|
'minified_js': minified_js,
|
|
|
|
})
|
|
|
|
|
2016-06-06 14:30:56 +02:00
|
|
|
env.install_gettext_translations(translation, True)
|
2016-04-21 08:48:33 +02:00
|
|
|
|
|
|
|
env.filters['slugify'] = slugify
|
|
|
|
env.filters['pluralize'] = pluralize
|
2016-05-12 20:35:35 +02:00
|
|
|
env.filters['display_list'] = display_list
|
2016-05-11 19:01:53 +02:00
|
|
|
env.filters['render_markdown_path'] = render_markdown_path
|
2016-04-21 08:48:33 +02:00
|
|
|
|
|
|
|
return env
|