2016-08-08 11:09:23 +02:00
|
|
|
from typing import Any
|
|
|
|
|
2020-04-04 01:47:18 +02:00
|
|
|
from django.conf import settings
|
|
|
|
from django.contrib.staticfiles.storage import staticfiles_storage
|
2020-06-11 00:54:34 +02:00
|
|
|
from django.template.defaultfilters import pluralize, slugify
|
2018-01-30 06:05:25 +01:00
|
|
|
from django.urls import reverse
|
2016-04-21 08:48:33 +02:00
|
|
|
from django.utils import translation
|
2019-03-04 13:55:32 +01:00
|
|
|
from django.utils.timesince import timesince
|
2016-04-21 08:48:33 +02:00
|
|
|
from jinja2 import Environment
|
2017-07-12 09:44:50 +02:00
|
|
|
from two_factor.templatetags.two_factor import device_action
|
2016-04-21 08:48:33 +02:00
|
|
|
|
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
|
|
|
|
|
|
|
|
2017-10-27 13:03:15 +02:00
|
|
|
def environment(**options: Any) -> Environment:
|
2016-04-21 08:48:33 +02:00
|
|
|
env = Environment(**options)
|
2020-09-03 05:32:15 +02:00
|
|
|
env.globals.update(
|
|
|
|
default_page_params={
|
2020-04-04 01:47:18 +02:00
|
|
|
'debug_mode': False,
|
|
|
|
'webpack_public_path': staticfiles_storage.url(
|
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
|
|
|
settings.WEBPACK_LOADER['DEFAULT']['BUNDLE_DIR_NAME'],
|
2020-04-04 01:47:18 +02:00
|
|
|
),
|
|
|
|
},
|
2020-09-03 05:32:15 +02:00
|
|
|
static=staticfiles_storage.url,
|
|
|
|
url=reverse,
|
|
|
|
render_markdown_path=render_markdown_path,
|
|
|
|
)
|
2016-04-21 08:48:33 +02:00
|
|
|
|
2017-08-25 20:01:20 +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
|
2017-07-12 09:44:50 +02:00
|
|
|
env.filters['device_action'] = device_action
|
2019-03-04 13:55:32 +01:00
|
|
|
env.filters['timesince'] = timesince
|
2016-04-21 08:48:33 +02:00
|
|
|
|
|
|
|
return env
|