-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.py.j2
86 lines (71 loc) · 2.13 KB
/
config.py.j2
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
83
84
85
86
# This file is generated from the ansible setup script
#
# If it needs to be customized differently, you should do the customizations there.
#
# Database configuration for torquedata
POSTGRES_DB_NAME="{{ supervisor_torquedata_name }}"
POSTGRES_DB_USER="{{ db_username }}"
POSTGRES_DB_PASSWORD="{{ db_password }}"
# Secret key as needed by django. See
# https://docs.djangoproject.com/en/3.1/ref/settings/#std:setting-SECRET_KEY
SECRET_KEY="{{ secret_key }}"
MEDIA_ROOT="{{ torquedata_install_directory }}uploads"
COLLECTIONS_ALIAS="competitions"
DOCUMENTS_ALIAS="proposals"
from core import utils
class RankBandFilter(utils.Filter):
def name(self):
return "rank_band"
def display_name(self):
return "Rank Band"
def document_value(self, document):
rank_str = False
try:
rank_str = document["Rank"]
except ValueError:
pass
if not rank_str:
return "Unranked"
try:
rank = int(rank_str)
if rank < 6:
return "1-5"
elif rank < 11:
return "6-10"
elif rank < 21:
return "11-20"
elif rank < 51:
return "21-50"
elif rank < 101:
return "51-100"
elif rank < 9999:
return "101+"
else:
return "Unranked"
except ValueError:
return "Unranked"
except TypeError:
return "Unranked"
def sort(self, names):
correct_order = [
"1-5",
"6-10",
"11-20",
"21-50",
"51-100",
"101+",
"Unranked",
]
names.sort(key=lambda name: correct_order.index(name) if name in correct_order else len(correct_order))
return names
class CompetitionName(utils.Filter):
def name(self):
return "competition_name"
def display_name(self):
return "Competition"
def document_value(self, document):
return document["Competition Name"] or "Unknown"
FILTERS = [
RankBandFilter(),
CompetitionName(),
]