ebauche espace chercheur
[auf_savoirs_en_partage_django.git] / auf_savoirs_en_partage / chercheurs / views.py
1 # -*- encoding: utf-8 -*-
2 from django.shortcuts import render_to_response
3 from django.template import Context, RequestContext
4 from forms import *
5
6 from auf_references_client.models import Discipline, TypeImplantation
7 from models import Personne
8
9 from django.contrib.auth.decorators import login_required
10
11 def chercheur_queryset (request):
12 list = Chercheur.objects.order_by("id")
13 pays = ""
14
15 simpleForm = RepertoireSearchForm (request.GET)
16 if simpleForm.is_valid ():
17 pays = simpleForm.cleaned_data["pays"]
18 if pays:
19 list = list.filter (pays = pays.pk)
20 fonction = simpleForm.cleaned_data["fonction"]
21 if fonction:
22 list = list.filter (fonction = fonction)
23 genre = simpleForm.cleaned_data["genre"]
24 if genre:
25 list = list.filter (personne__genre=genre)
26 discipline = simpleForm.cleaned_data["discipline"]
27 if discipline:
28 list = list.filter (discipline=discipline)
29 mots_cles = simpleForm.cleaned_data["mots_cles"]
30 if mots_cles:
31 list = list.filter (personne__nom__icontains=mots_cles)
32 return list
33
34 def repertoire(request):
35 """Mock up du répertoire"""
36
37 chercheurs = chercheur_queryset (request)
38 repertoire_form = RepertoireSearchForm (request.GET)
39
40 nb_chercheurs = chercheurs.count()
41 variables = { 'chercheurs': chercheurs,
42 'nb_chercheurs': nb_chercheurs,
43 'repertoire_form': repertoire_form,
44 }
45 return render_to_response ("chercheurs/repertoire.html", \
46 Context (variables),
47 context_instance = RequestContext(request))
48
49 def inscription(request):
50 if request.method == 'POST':
51 personne_form = PersonneForm (request.POST, prefix="personne")
52 chercheur_form = ChercheurForm (request.POST, prefix="chercheur")
53 etablissement_form = EtablissementForm (request.POST, prefix="etablissement")
54 discipline_form = DisciplineForm (request.POST, prefix="discipline")
55
56 if personne_form.is_valid():
57 if chercheur_form.is_valid():
58 c = chercheur_form.save(commit=False)
59
60 etablissement_form = EtablissementForm (request.POST, prefix="etablissement", instance=c)
61 discipline_form = DisciplineForm (request.POST, prefix="discipline", instance=c)
62
63 if etablissement_form.is_valid() and discipline_form.is_valid():
64 etablissement_form.save(commit=False)
65 discipline_form.save(commit=False)
66 p = personne_form.save()
67 c.personne = p
68 c.save()
69 else:
70 personne_form = PersonneForm(prefix="personne")
71 chercheur_form = ChercheurForm(prefix="chercheur")
72 etablissement_form = EtablissementForm(prefix="etablissement")
73 discipline_form = DisciplineForm(prefix="discipline")
74
75 variables = { 'personne_form': personne_form,
76 'chercheur_form': chercheur_form,
77 'etablissement_form': etablissement_form,
78 'discipline_form': discipline_form,
79 }
80
81 return render_to_response ("chercheurs/inscription.html", \
82 Context (variables),
83 context_instance = RequestContext(request))
84
85
86 def perso(request):
87 """Mock up de l'espace perso"""
88 context_instance = RequestContext(request)
89 chercheur = context_instance['user_chercheur']
90 variables = { 'chercheur': chercheur,
91 }
92 return render_to_response ("chercheurs/perso.html", \
93 Context (variables),
94 context_instance = RequestContext(request))
95
96 def retrieve(request, id):
97 """Fiche du chercheur"""
98 chercheur = Chercheur.objects.get(id=id)
99 variables = { 'chercheur': chercheur,
100 }
101 return render_to_response ("chercheurs/retrieve.html", \
102 Context (variables),
103 context_instance = RequestContext(request))