ebauche espace chercheur
[auf_savoirs_en_partage_django.git] / auf_savoirs_en_partage / chercheurs / views.py
CommitLineData
588d6b93 1# -*- encoding: utf-8 -*-
932eef9a
AJ
2from django.shortcuts import render_to_response
3from django.template import Context, RequestContext
4from forms import *
5
6from auf_references_client.models import Discipline, TypeImplantation
7from models import Personne
8
9af73c99 9from django.contrib.auth.decorators import login_required
13146d99
AJ
10
11def 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
588d6b93 34def repertoire(request):
35 """Mock up du répertoire"""
13146d99
AJ
36
37 chercheurs = chercheur_queryset (request)
38 repertoire_form = RepertoireSearchForm (request.GET)
39
9f7c169e 40 nb_chercheurs = chercheurs.count()
588d6b93 41 variables = { 'chercheurs': chercheurs,
9f7c169e 42 'nb_chercheurs': nb_chercheurs,
13146d99 43 'repertoire_form': repertoire_form,
588d6b93 44 }
45 return render_to_response ("chercheurs/repertoire.html", \
46 Context (variables),
47 context_instance = RequestContext(request))
48
932eef9a
AJ
49def inscription(request):
50 if request.method == 'POST':
51 personne_form = PersonneForm (request.POST, prefix="personne")
52 chercheur_form = ChercheurForm (request.POST, prefix="chercheur")
7c596de2
AJ
53 etablissement_form = EtablissementForm (request.POST, prefix="etablissement")
54 discipline_form = DisciplineForm (request.POST, prefix="discipline")
55
932eef9a
AJ
56 if personne_form.is_valid():
57 if chercheur_form.is_valid():
932eef9a 58 c = chercheur_form.save(commit=False)
7c596de2
AJ
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()
932eef9a
AJ
69 else:
70 personne_form = PersonneForm(prefix="personne")
71 chercheur_form = ChercheurForm(prefix="chercheur")
7c596de2
AJ
72 etablissement_form = EtablissementForm(prefix="etablissement")
73 discipline_form = DisciplineForm(prefix="discipline")
932eef9a
AJ
74
75 variables = { 'personne_form': personne_form,
76 'chercheur_form': chercheur_form,
7c596de2
AJ
77 'etablissement_form': etablissement_form,
78 'discipline_form': discipline_form,
932eef9a
AJ
79 }
80
81 return render_to_response ("chercheurs/inscription.html", \
82 Context (variables),
83 context_instance = RequestContext(request))
9af73c99
AJ
84
85
86def perso(request):
588d6b93 87 """Mock up de l'espace perso"""
9af73c99
AJ
88 context_instance = RequestContext(request)
89 chercheur = context_instance['user_chercheur']
588d6b93 90 variables = { 'chercheur': chercheur,
91 }
92 return render_to_response ("chercheurs/perso.html", \
93 Context (variables),
94 context_instance = RequestContext(request))
da091176 95
96def 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))