Commit | Line | Data |
---|---|---|
6f8d521e EMS |
1 | # coding: utf-8 |
2 | ||
3 | from django import template | |
4 | from django.utils.encoding import smart_unicode | |
5 | ||
22b31ca9 | 6 | from chercheurs.models import GroupeChercheur, DomaineRecherche, GENRE_CHOICES, STATUT_CHOICES |
693c606b | 7 | from auf.django.references.models import Region, Pays |
6f8d521e EMS |
8 | from savoirs.models import Discipline |
9 | ||
10 | register = template.Library() | |
11 | ||
12 | OUI_NON_CHOICES = [(1, 'Oui'), (0, 'Non')] | |
13 | ||
14 | @register.inclusion_tag('admin/filter.html', takes_context=True) | |
15 | def filter_genre(context): | |
16 | return {'title': 'genre', | |
17 | 'choices': prepare_choices(GENRE_CHOICES, 'genre', context)} | |
18 | ||
19 | @register.inclusion_tag('admin/filter.html', takes_context=True) | |
20 | def filter_statut(context): | |
21 | return {'title': 'statut', | |
22 | 'choices': prepare_choices(STATUT_CHOICES, 'statut', context)} | |
23 | ||
24 | @register.inclusion_tag('admin/filter.html', takes_context=True) | |
25 | def filter_membre_reseau_institutionnel(context): | |
26 | return {'title': u"appartenance aux instances d'un réseau institutionnel de l'AUF", | |
27 | 'choices': prepare_choices(OUI_NON_CHOICES, 'membre_reseau_institutionnel', context)} | |
28 | ||
29 | @register.inclusion_tag('admin/filter.html', takes_context=True) | |
30 | def filter_membre_instance_auf(context): | |
31 | return {'title': u"appartenance à une instance de l'AUF", | |
32 | 'choices': prepare_choices(OUI_NON_CHOICES, 'membre_instance_auf', context)} | |
33 | ||
34 | @register.inclusion_tag('admin/filter.html', takes_context=True) | |
35 | def filter_discipline(context): | |
36 | return {'title': u"discipline", | |
37 | 'choices': prepare_choices(Discipline.objects.values_list('id', 'nom'), 'discipline', context)} | |
38 | ||
39 | @register.inclusion_tag('admin/filter.html', takes_context=True) | |
40 | def filter_region(context): | |
41 | return {'title': u"région", | |
15ceabe6 EMS |
42 | 'choices': prepare_choices(Region.objects.values_list('id', 'nom'), 'region', context, remove=['pays', 'nord_sud'])} |
43 | ||
44 | @register.inclusion_tag('admin/filter.html', takes_context=True) | |
45 | def filter_nord_sud(context): | |
46 | return {'title': u'nord/sud', | |
47 | 'choices': prepare_choices([('Nord', 'Nord'), ('Sud', 'Sud')], 'nord_sud', context, remove=['pays', 'region'])} | |
6f8d521e EMS |
48 | |
49 | @register.inclusion_tag('admin/filter.html', takes_context=True) | |
22b31ca9 | 50 | def filter_groupe_chercheurs(context): |
d26ca87a | 51 | return {'title': u"communautés de chercheurs", |
22b31ca9 PP |
52 | 'choices': prepare_choices(GroupeChercheur.objects.values_list('id', 'nom'), 'groupes', context)} |
53 | ||
54 | @register.inclusion_tag('admin/filter.html', takes_context=True) | |
55 | def filter_domaine_recherche(context): | |
6f8d521e | 56 | return {'title': u"domaine de recherche", |
22b31ca9 | 57 | 'choices': prepare_choices(DomaineRecherche.objects.values_list('id', 'nom'), 'groupes', context)} |
6f8d521e EMS |
58 | |
59 | @register.inclusion_tag('admin/filter.html', takes_context=True) | |
60 | def filter_expert(context): | |
61 | return {'title': u"expert", | |
62 | 'choices': prepare_choices(OUI_NON_CHOICES, 'expert', context)} | |
63 | ||
64 | def prepare_choices(choices, query_param, context, remove=[]): | |
65 | request = context['request'] | |
66 | cl = context['cl'] | |
67 | query_val = request.GET.get(query_param) | |
68 | result = [{'selected': query_val is None, | |
69 | 'query_string': cl.get_query_string({}, [query_param] + remove), | |
70 | 'display': 'Tout'}] | |
71 | for k, v in choices: | |
72 | result.append({'selected': smart_unicode(k) == query_val, | |
73 | 'query_string': cl.get_query_string({query_param: k}, remove), | |
74 | 'display': v}) | |
75 | return result |