-
Notifications
You must be signed in to change notification settings - Fork 0
/
jinjafilters.py
35 lines (19 loc) · 1.03 KB
/
jinjafilters.py
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
import os
import jinja2
__author__ = 'jotegui'
def query_countries_format(query_countries):
return [["Country", "Events"]]+[[str(x.query_country), x.times] for x in query_countries if x.query_country != "Unknown"]
def query_dates_format(query_dates):
return [["Date", "Events"]]+sorted([[x.query_date.day, x.times] for x in query_dates])
def query_terms_format(query_terms):
return [["Terms", "Records retrieved"]]+[["%s (%d time/s)" % (str(x.query_terms), x.times), x.records] for x in query_terms]
def percentage_format(fl):
return str(round(fl, 2))+"%"
JINJA_ENVIRONMENT = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.join(os.path.dirname(__file__), 'templates')),
extensions=['jinja2.ext.autoescape'],
autoescape=True)
JINJA_ENVIRONMENT.filters['querycountriesformat'] = query_countries_format
JINJA_ENVIRONMENT.filters['querydatesformat'] = query_dates_format
JINJA_ENVIRONMENT.filters['querytermsformat'] = query_terms_format
JINJA_ENVIRONMENT.filters['percentageformat'] = percentage_format