-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjinjacfg.py
More file actions
52 lines (36 loc) · 1.49 KB
/
jinjacfg.py
File metadata and controls
52 lines (36 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os
# Third-party imports
import jinja2
# Internal project imports
from constants import error_messages
def timestamp_format(value, f="%d %B %Y, %H:%M:%S"):
return value.strftime(f).lstrip('0')
def edit_version_url(article_url, version_id):
if article_url == '/':
return '/_edit/_version/{}'.format(version_id)
return '/_edit{}/_version/{}'.format(article_url, version_id)
def delete_version_url(article_url, version_id):
if article_url == '/':
return '/_delete/_version/{}'.format(version_id)
return '/_delete{}/_version/{}'.format(article_url, version_id)
def view_version_url(article_url, version_id):
if article_url == '/':
return '/_version/{}'.format(version_id)
return '{}/_version/{}'.format(article_url, version_id)
def resolve_msg_from_errtype(error_type):
return error_messages[error_type]
jinja_environment = jinja2.Environment(
autoescape=True, loader=jinja2.FileSystemLoader(
os.path.join(os.path.dirname(__file__), 'templates')))
jinja_environment.lstrip_blocks = True
jinja_environment.trim_blocks = True
detailed_error_messages = jinja_environment.get_template(
'wiki/detailed_error_messages.html').module
jinja_environment.filters['timestampformat'] = timestamp_format
jinja_environment.globals.update({
'view_version_url': view_version_url,
'edit_version_url': edit_version_url,
'delete_version_url': delete_version_url,
'resolve_msg_from_errtype': resolve_msg_from_errtype,
'getattr': getattr
})