-
Notifications
You must be signed in to change notification settings - Fork 0
/
views.py
69 lines (52 loc) · 1.63 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
from jinja2 import Environment, PackageLoader, select_autoescape
from models import User
from common.unicode import emoji
# setting Jinja2-specified params
env = Environment(
loader=PackageLoader("views"),
autoescape=select_autoescape()
)
env.trim_blocks = True
env.lstrip_blocks = True
def hello(username: str):
"""
Render basic hello template
"""
template = env.get_template("hello.jinja2")
return template.render(username=username, emoji=emoji)
def charlist(user: User):
"""
Render list of user's characters, their throws and attributes.
"""
template = env.get_template("charlist.jinja2")
return template.render(user=user, 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 roll(roller: object, hand: object):
"""
Render roll template
"""
template = env.get_template("roll.jinja2")
return template.render(roller=roller, hand=hand, emoji=emoji)
def statistics(stats):
"""
Render statistics template
"""
template = env.get_template("statistics.jinja2")
return template.render(stats=stats, emoji=emoji)
def info():
"""
Render info template
"""
template = env.get_template("info.jinja2")
return template.render(emoji=emoji)