Commit | Line | Data |
---|---|---|
9af73c99 AJ |
1 | # -*- encoding: utf-8 -*- |
2 | ||
bae03b7b | 3 | import re |
321c4e19 PP |
4 | from django.http import Http404 |
5 | ||
6 | ||
bae03b7b EMS |
7 | DISCIPLINE_REGION_RE = re.compile(r'/(discipline/(?P<discipline>\d+)/)?(region/(?P<region>\d+)/)?') |
8 | def discipline_region(request): | |
3b828312 PP |
9 | discipline = request.GET.get('discipline', None) |
10 | region = request.GET.get('region', None) | |
11 | ||
12 | if not discipline and not region: | |
13 | match = DISCIPLINE_REGION_RE.match(request.path) | |
14 | discipline = match.group('discipline') | |
15 | region = match.group('region') | |
16 | ||
321c4e19 PP |
17 | try: |
18 | discipline = discipline and int(discipline) | |
19 | region = region and int(region) | |
20 | except ValueError: | |
21 | raise Http404 | |
3b828312 | 22 | |
bae03b7b | 23 | return dict(discipline_active=discipline, region_active=region) |