|
2 | 2 |
|
3 | 3 | # Valid parameter values as seen at
|
4 | 4 | # https://github.com/gitcoinco/web/blob/84babc30611c281c817582b4d677dda6366def83/app/dashboard/models.py#L119-L168
|
5 |
| -options = { |
| 5 | +OPTIONS = { |
6 | 6 | 'experience_level': ['Beginner', 'Intermediate', 'Advanced', 'Unknown'],
|
7 | 7 | 'project_length': ['Hours', 'Days', 'Weeks', 'Months', 'Unknown'],
|
8 | 8 | 'bounty_type': ['Bug', 'Security', 'Feature', 'Unknown'],
|
|
25 | 25 | ]
|
26 | 26 | }
|
27 | 27 |
|
| 28 | + |
28 | 29 | def _validate_options(field_name, value):
|
29 | 30 | """Validate values for the given field name."""
|
30 |
| - if value in options[field_name]: |
| 31 | + if value in OPTIONS[field_name]: |
31 | 32 | return value
|
32 | 33 | msg = 'Unknown value "{val}" for field "{name}".'
|
33 | 34 | raise ValueError(msg.format(val=value, name=field_name))
|
34 | 35 |
|
| 36 | + |
35 | 37 | def experience_level(value):
|
36 | 38 | """Validate values for "experience_level"."""
|
37 | 39 | return _validate_options('experience_level', value)
|
38 | 40 |
|
| 41 | + |
39 | 42 | def project_length(value):
|
40 | 43 | """Validate values for "project_length"."""
|
41 | 44 | return _validate_options('project_length', value)
|
42 | 45 |
|
| 46 | + |
43 | 47 | def bounty_type(value):
|
44 | 48 | """Validate values for "bounty_type"."""
|
45 | 49 | return _validate_options('bounty_type', value)
|
46 | 50 |
|
| 51 | + |
47 | 52 | def idx_status(value):
|
48 | 53 | """Validate values for "idx_status"."""
|
49 | 54 | return _validate_options('idx_status', value)
|
50 | 55 |
|
| 56 | + |
51 | 57 | def order_by(direction):
|
52 | 58 | """Validate values for "order_by"."""
|
53 |
| - if direction in options['order_by']: |
| 59 | + if direction in OPTIONS['order_by']: |
54 | 60 | return direction
|
55 |
| - if direction[0:1] == '-' and direction[1:] in options['order_by']: |
| 61 | + if direction[0:1] == '-' and direction[1:] in OPTIONS['order_by']: |
56 | 62 | return direction
|
57 | 63 | msg = 'Unknown direction "{dir}" to order by.'
|
58 | 64 | raise ValueError(msg.format(dir=direction))
|
0 commit comments