-
Notifications
You must be signed in to change notification settings - Fork 2
/
filters.py
57 lines (50 loc) · 1.43 KB
/
filters.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
from honomara_members_site import app, db
def fmt_course(course, long=False):
show_name = course.show_name
distance = course.distance
time = course.time
t = course.type
ret = show_name
if t == 'road':
if long:
if ret:
ret += '({}km ロード)'.format(distance)
else:
ret = '{}kmロード'.format(distance)
elif not ret:
ret = '{}km'.format(int(distance))
elif t == 'trail':
if long and ret:
ret += '({}km トレイル)'.format(distance)
elif not ret:
ret = '{}kmトレイル'.format(int(distance))
elif t == 'time':
if not ret:
ret = '{}時間走'.format(int(distance))
elif t == 'relay':
if not ret:
ret = '{}時間リレー'.format(int(distance))
if not ret:
ret = '不明種目({}km ,{}時間, {})'.format(distance, time, t)
return ret
def fmt_time(time, long=False):
if time is None:
return "未入力"
ms = time % 1000
time //= 1000
s = time % 60
time //= 60
m = time % 60
time //= 60
h = time
ret = ''
if h > 0:
ret += '{}°'.format(h)
if h > 0 or m > 0:
ret += "{:02}′".format(m)
ret += '{:02}'.format(s)
if long:
ret += '″{:02}'.format(ms)
return ret
app.jinja_env.filters["fmt_course"] = fmt_course
app.jinja_env.filters["fmt_time"] = fmt_time