Edition basique d'un profil
[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
b3e1079e 7from models import Personne, Utilisateur
932eef9a 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
b3e1079e
AJ
86def edit(request):
87 """Edition d'un chercheur"""
88 context_instance = RequestContext(request)
89 chercheur = context_instance['user_chercheur']
90 if request.method == 'POST':
91 personne_form = PersonneEditForm(request.POST, prefix="personne", instance=chercheur.personne)
92 personne_form.save()
93 else:
94 personne_form = PersonneEditForm(prefix="personne", instance=chercheur.personne)
95
96 variables = { 'chercheur': chercheur,
97 'personne_form':personne_form,
98 }
99 return render_to_response ("chercheurs/edit.html", \
100 Context (variables),
101 context_instance = RequestContext(request))
102
103
104
9af73c99 105def perso(request):
588d6b93 106 """Mock up de l'espace perso"""
9af73c99
AJ
107 context_instance = RequestContext(request)
108 chercheur = context_instance['user_chercheur']
588d6b93 109 variables = { 'chercheur': chercheur,
110 }
111 return render_to_response ("chercheurs/perso.html", \
112 Context (variables),
113 context_instance = RequestContext(request))
da091176 114
115def retrieve(request, id):
116 """Fiche du chercheur"""
117 chercheur = Chercheur.objects.get(id=id)
118 variables = { 'chercheur': chercheur,
119 }
120 return render_to_response ("chercheurs/retrieve.html", \
121 Context (variables),
122 context_instance = RequestContext(request))