Site retrait de la verification de la validite des urls
[auf_savoirs_en_partage_django.git] / auf_savoirs_en_partage / chercheurs / views.py
1 # -*- encoding: utf-8 -*-
2 import hashlib
3 from django.shortcuts import render_to_response
4 from django.http import HttpResponseRedirect
5 from django.template import Context, RequestContext
6 from django.core.urlresolvers import reverse
7 from forms import *
8
9 from auf_references_client.models import Discipline, TypeImplantation
10 from models import Personne, Utilisateur
11
12 from django.contrib.auth.decorators import login_required
13
14 def chercheur_queryset (request):
15 list = Chercheur.objects.order_by("id")
16 pays = ""
17
18 simpleForm = RepertoireSearchForm (request.GET)
19 if simpleForm.is_valid ():
20 pays = simpleForm.cleaned_data["pays"]
21 if pays:
22 list = list.filter (nationalite = pays.pk)
23 fonction = simpleForm.cleaned_data["fonction"]
24 if fonction:
25 list = list.filter (fonction = fonction)
26 genre = simpleForm.cleaned_data["genre"]
27 if genre:
28 list = list.filter (personne__genre=genre)
29 discipline = simpleForm.cleaned_data["discipline"]
30 if discipline:
31 list = list.filter (discipline=discipline)
32 #mots_cles = simpleForm.cleaned_data["mots_cles"]
33 #if mots_cles:
34 # list = list.filter (personne__nom__icontains=mots_cles)
35 return list
36
37 def repertoire(request):
38 """Mock up du répertoire"""
39
40 chercheurs = chercheur_queryset (request)
41 repertoire_form = RepertoireSearchForm (request.GET)
42
43 nb_chercheurs = chercheurs.count()
44 variables = { 'chercheurs': chercheurs,
45 'nb_chercheurs': nb_chercheurs,
46 'repertoire_form': repertoire_form,
47 }
48 return render_to_response ("chercheurs/repertoire.html", \
49 Context (variables),
50 context_instance = RequestContext(request))
51
52 def inscription(request):
53 if request.method == 'POST':
54 personne_form = PersonneForm (request.POST, prefix="personne")
55 chercheur_form = ChercheurForm (request.POST, prefix="chercheur")
56 etablissement_form = EtablissementForm (request.POST, prefix="etablissement")
57 etablissement_autre_form = EtablissementAutreForm(request.POST, prefix="etablissement_autre")
58 discipline_form = DisciplineForm (request.POST, prefix="discipline")
59 publication1_form = PublicationForm (request.POST, prefix="publication1")
60 publication2_form = PublicationForm (request.POST, prefix="publication2")
61 publication3_form = PublicationForm (request.POST, prefix="publication3")
62 publication4_form = PublicationForm (request.POST, prefix="publication4")
63 these_form = TheseForm(request.POST, prefix="these")
64
65 if personne_form.is_valid():
66 if chercheur_form.is_valid():
67 c = chercheur_form.save(commit=False)
68
69 etablissement_form = EtablissementForm (request.POST, prefix="etablissement", instance=c)
70 discipline_form = DisciplineForm (request.POST, prefix="discipline", instance=c)
71
72 if etablissement_form.is_valid() and discipline_form.is_valid() and these_form.is_valid():
73 if publication1_form.is_valid() and publication1_form.cleaned_data['titre']:
74 pub = publication1_form.save()
75 c.publication1 = pub
76 if publication2_form.is_valid() and publication2_form.cleaned_data['titre']:
77 pub = publication2_form.save()
78 c.publication2 = pub
79 if publication3_form.is_valid() and publication3_form.cleaned_data['titre']:
80 pub = publication3_form.save()
81 c.publication3 = pub
82 if publication4_form.is_valid() and publication4_form.cleaned_data['titre']:
83 pub = publication4_form.save()
84 c.publication4 = pub
85 these = these_form.save()
86 c.these = these
87 etablissement_form.save(commit=False)
88 etablissement_autre_form.save(commit=False)
89 discipline_form.save(commit=False)
90 #encodage du mot de passe de l'utilisateur (refactorer car c'est pas clean
91 #et c'est pas la bonne place pour faire ca - AJ
92 personne_form.cleaned_data['password'] = hashlib.md5(personne_form.cleaned_data['password']).hexdigest()
93 p = personne_form.save()
94 c.personne = p
95 c.save()
96 return HttpResponseRedirect(reverse('chercheurs.views.retrieve', args=(c.id,)))
97 else:
98 personne_form = PersonneForm(prefix="personne")
99 chercheur_form = ChercheurForm(prefix="chercheur")
100 etablissement_form = EtablissementForm(prefix="etablissement")
101 etablissement_autre_form = EtablissementAutreForm(prefix="etablissement_autre")
102 discipline_form = DisciplineForm(prefix="discipline")
103 publication1_form = PublicationForm(prefix="publication1")
104 publication2_form = PublicationForm(prefix="publication2")
105 publication3_form = PublicationForm(prefix="publication3")
106 publication4_form = PublicationForm(prefix="publication4")
107 these_form = TheseForm(prefix="these")
108
109 variables = { 'personne_form': personne_form,
110 'chercheur_form': chercheur_form,
111 'etablissement_form': etablissement_form,
112 'discipline_form': discipline_form,
113 'etablissement_autre_form': etablissement_autre_form,
114 'publication1_form': publication1_form,
115 'publication2_form': publication2_form,
116 'publication3_form': publication3_form,
117 'publication4_form': publication4_form,
118 'these_form': these_form,
119 }
120
121 return render_to_response ("chercheurs/inscription.html", \
122 Context (variables),
123 context_instance = RequestContext(request))
124
125
126 def edit(request):
127 """Edition d'un chercheur"""
128 context_instance = RequestContext(request)
129 chercheur = context_instance['user_chercheur']
130 if request.method == 'POST':
131 personne_form = PersonneEditForm(request.POST, prefix="personne", instance=chercheur.personne)
132 #chercheur_form = ChercheurForm (request.POST, prefix="chercheur", instance=chercheur)
133 etablissement_form = EtablissementForm(request.POST, prefix="etablissement", instance=chercheur)
134 etablissement_autre_form = EtablissementAutreForm(request.POST, prefix="etablissement_autre", instance=chercheur)
135 discipline_form = DisciplineForm(request.POST, prefix="discipline", instance=chercheur)
136 publication1_form = PublicationForm(request.POST, prefix="publication1", instance=chercheur.publication1)
137 publication2_form = PublicationForm(request.POST, prefix="publication2", instance=chercheur.publication2)
138 publication3_form = PublicationForm(request.POST, prefix="publication3", instance=chercheur.publication3)
139 publication4_form = PublicationForm(request.POST, prefix="publication4", instance=chercheur.publication4)
140 these_form = TheseForm(request.POST, prefix="these", instance=chercheur.these)
141
142
143 if( personne_form.is_valid() and discipline_form.is_valid() and publication1_form.is_valid() and publication2_form.is_valid() and publication3_form.is_valid() and publication4_form.is_valid() and these_form.is_valid() ):
144 personne_form.save()
145 #chercheur_form.save()
146 discipline_form.save()
147 publication1_form.save()
148 publication2_form.save()
149 publication3_form.save()
150 publication4_form.save()
151 these_form.save()
152 else:
153 personne_form = PersonneEditForm(prefix="personne", instance=chercheur.personne)
154 #chercheur_form = ChercheurForm (prefix="chercheur", instance=chercheur)
155 etablissement_form = EtablissementForm(prefix="etablissement", instance=chercheur)
156 etablissement_autre_form = EtablissementAutreForm(prefix="etablissement_autre", instance=chercheur)
157 discipline_form = DisciplineForm(prefix="discipline", instance=chercheur)
158 publication1_form = PublicationForm(prefix="publication1", instance=chercheur.publication1)
159 publication2_form = PublicationForm(prefix="publication2", instance=chercheur.publication2)
160 publication3_form = PublicationForm(prefix="publication3", instance=chercheur.publication3)
161 publication4_form = PublicationForm(prefix="publication4", instance=chercheur.publication4)
162 these_form = TheseForm(prefix="these", instance=chercheur.these)
163
164 variables = { 'chercheur': chercheur,
165 'personne_form':personne_form,
166 #'chercheur_form': chercheur_form,
167 'etablissement_form': etablissement_form,
168 'discipline_form': discipline_form,
169 'etablissement_autre_form': etablissement_autre_form,
170 'publication1_form': publication1_form,
171 'publication2_form': publication2_form,
172 'publication3_form': publication3_form,
173 'publication4_form': publication4_form,
174 'these_form': these_form,
175 }
176 return render_to_response ("chercheurs/edit.html", \
177 Context (variables),
178 context_instance = RequestContext(request))
179
180
181
182 def perso(request):
183 """Mock up de l'espace perso"""
184 context_instance = RequestContext(request)
185 chercheur = context_instance['user_chercheur']
186 variables = { 'chercheur': chercheur,
187 }
188 return render_to_response ("chercheurs/perso.html", \
189 Context (variables),
190 context_instance = RequestContext(request))
191
192 def retrieve(request, id):
193 """Fiche du chercheur"""
194 chercheur = Chercheur.objects.get(id=id)
195 variables = { 'chercheur': chercheur,
196 }
197 return render_to_response ("chercheurs/retrieve.html", \
198 Context (variables),
199 context_instance = RequestContext(request))