Merge branch 'master' into test
[auf_savoirs_en_partage_django.git] / auf_savoirs_en_partage / context_processors.py
1 # -*- encoding: utf-8 -*-
2
3 import re
4 from django.http import Http404
5
6
7 DISCIPLINE_REGION_RE = re.compile(r'/(discipline/(?P<discipline>\d+)/)?(region/(?P<region>\d+)/)?')
8 def discipline_region(request):
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
17 try:
18 discipline = discipline and int(discipline)
19 region = region and int(region)
20 except ValueError:
21 raise Http404
22
23 return dict(discipline_active=discipline, region_active=region)