Filtrage permanent des disciplines et des régions.
[auf_savoirs_en_partage_django.git] / auf_savoirs_en_partage / context_processors.py
1 # -*- encoding: utf-8 -*-
2
3 import re
4 from chercheurs.models import Chercheur, Utilisateur
5
6 def user_chercheur(request):
7 user_chercheur = Chercheur.objects.none()
8 user_sep = Utilisateur.objects.none()
9 if request.user.is_authenticated():
10 try:
11 user_chercheur = Chercheur.objects.get(personne__courriel=request.user.email)
12 user_sep = Utilisateur.objects.get(id=user_chercheur.personne_id)
13 except:
14 pass
15 return {'user_chercheur': user_chercheur,
16 'user_sep': user_sep,}
17
18 DISCIPLINE_REGION_RE = re.compile(r'/(discipline/(?P<discipline>\d+)/)?(region/(?P<region>\d+)/)?')
19 def discipline_region(request):
20 match = DISCIPLINE_REGION_RE.match(request.path)
21 discipline = match.group('discipline')
22 region = match.group('region')
23 discipline = discipline and int(discipline)
24 region = region and int(region)
25 return dict(discipline_active=discipline, region_active=region)