-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.py
82 lines (60 loc) · 2.01 KB
/
views.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from datetime import datetime
from jinja2 import Environment, PackageLoader, select_autoescape
from unicode import emoji
# setting Jinja2-specified params
env = Environment(
loader=PackageLoader('views'),
autoescape=select_autoescape()
)
env.trim_blocks = True
env.lstrip_blocks = True
def format_datetime(value: datetime,
format_string: str):
return value.strftime(format_string)
env.filters['format_datetime'] = format_datetime
def hello(username: str):
"""
Render basic hello template
"""
with open('version.txt', 'r') as fd:
ver = fd.read()
template = env.get_template("hello.jinja2")
return template.render(username=username, version=ver, emoji=emoji)
def command_help(command: str, error_text: str = ''):
"""
Send help message about certain command
"""
template = env.get_template(f"commands/{command}.jinja2")
return template.render(error_text=error_text, emoji=emoji)
def error(error_text: str):
"""
Render error_text into a standard error template
"""
template = env.get_template("error.jinja2")
return template.render(error_text=error_text, emoji=emoji)
def got_answer(answer, username, puzzle):
"""
Render got_answer template
"""
template = env.get_template("gotanswer.jinja2")
return template.render(answer=answer, username=username,
puzzle=puzzle, emoji=emoji)
def got_puzzle(puzzle):
"""
Render got_puzzle template
"""
template = env.get_template("gotpuzzle.jinja2")
return template.render(puzzle=puzzle, emoji=emoji)
def show_answers(puzzle):
"""
Render show_answers template
"""
template = env.get_template("showanswers.jinja2")
return template.render(puzzle=puzzle, emoji=emoji)
def show_recent(answers, auth: bool = False):
"""
Render show_recent template
"""
template = env.get_template("showrecent.jinja2")
return template.render(answers=answers, auth=auth,
emoji=emoji)