Commit | Line | Data |
---|---|---|
588d6b93 | 1 | # -*- encoding: utf-8 -*- |
5ecd9e43 | 2 | import hashlib |
932eef9a | 3 | from django.shortcuts import render_to_response |
5ecd9e43 | 4 | from django.http import HttpResponseRedirect |
932eef9a | 5 | from django.template import Context, RequestContext |
5ecd9e43 | 6 | from django.core.urlresolvers import reverse |
932eef9a AJ |
7 | from forms import * |
8 | ||
9 | from auf_references_client.models import Discipline, TypeImplantation | |
b3e1079e | 10 | from models import Personne, Utilisateur |
932eef9a | 11 | |
9af73c99 | 12 | from django.contrib.auth.decorators import login_required |
13146d99 AJ |
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: | |
6befc7c9 | 22 | list = list.filter (nationalite = pays.pk) |
13146d99 AJ |
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) | |
020b4d09 AJ |
32 | #mots_cles = simpleForm.cleaned_data["mots_cles"] |
33 | #if mots_cles: | |
34 | # list = list.filter (personne__nom__icontains=mots_cles) | |
13146d99 AJ |
35 | return list |
36 | ||
588d6b93 | 37 | def repertoire(request): |
38 | """Mock up du répertoire""" | |
13146d99 AJ |
39 | |
40 | chercheurs = chercheur_queryset (request) | |
41 | repertoire_form = RepertoireSearchForm (request.GET) | |
42 | ||
9f7c169e | 43 | nb_chercheurs = chercheurs.count() |
588d6b93 | 44 | variables = { 'chercheurs': chercheurs, |
9f7c169e | 45 | 'nb_chercheurs': nb_chercheurs, |
13146d99 | 46 | 'repertoire_form': repertoire_form, |
588d6b93 | 47 | } |
48 | return render_to_response ("chercheurs/repertoire.html", \ | |
49 | Context (variables), | |
50 | context_instance = RequestContext(request)) | |
51 | ||
932eef9a AJ |
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") | |
7c596de2 | 56 | etablissement_form = EtablissementForm (request.POST, prefix="etablissement") |
00755d9b | 57 | etablissement_autre_form = EtablissementAutreForm(request.POST, prefix="etablissement_autre") |
7c596de2 | 58 | discipline_form = DisciplineForm (request.POST, prefix="discipline") |
00755d9b AJ |
59 | publication1_form = PublicationForm (request.POST, prefix="publication1") |
60 | publication2_form = PublicationForm (request.POST, prefix="publication2") | |
61 | publication3_form = PublicationForm (request.POST, prefix="publication3") | |
f810842d AJ |
62 | publication4_form = PublicationForm (request.POST, prefix="publication4") |
63 | these_form = TheseForm(request.POST, prefix="these") | |
7c596de2 | 64 | |
932eef9a AJ |
65 | if personne_form.is_valid(): |
66 | if chercheur_form.is_valid(): | |
932eef9a | 67 | c = chercheur_form.save(commit=False) |
7c596de2 AJ |
68 | |
69 | etablissement_form = EtablissementForm (request.POST, prefix="etablissement", instance=c) | |
70 | discipline_form = DisciplineForm (request.POST, prefix="discipline", instance=c) | |
71 | ||
f810842d | 72 | if etablissement_form.is_valid() and discipline_form.is_valid() and these_form.is_valid(): |
6befc7c9 | 73 | if publication1_form.is_valid() and publication1_form.cleaned_data['titre']: |
00755d9b AJ |
74 | pub = publication1_form.save() |
75 | c.publication1 = pub | |
6befc7c9 | 76 | if publication2_form.is_valid() and publication2_form.cleaned_data['titre']: |
00755d9b AJ |
77 | pub = publication2_form.save() |
78 | c.publication2 = pub | |
6befc7c9 | 79 | if publication3_form.is_valid() and publication3_form.cleaned_data['titre']: |
00755d9b AJ |
80 | pub = publication3_form.save() |
81 | c.publication3 = pub | |
6befc7c9 | 82 | if publication4_form.is_valid() and publication4_form.cleaned_data['titre']: |
00755d9b AJ |
83 | pub = publication4_form.save() |
84 | c.publication4 = pub | |
f810842d AJ |
85 | these = these_form.save() |
86 | c.these = these | |
00755d9b AJ |
87 | etablissement_form.save(commit=False) |
88 | etablissement_autre_form.save(commit=False) | |
7c596de2 | 89 | discipline_form.save(commit=False) |
5ecd9e43 AJ |
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() | |
7c596de2 AJ |
93 | p = personne_form.save() |
94 | c.personne = p | |
95 | c.save() | |
f810842d | 96 | return HttpResponseRedirect(reverse('chercheurs.views.retrieve', args=(c.id,))) |
932eef9a AJ |
97 | else: |
98 | personne_form = PersonneForm(prefix="personne") | |
99 | chercheur_form = ChercheurForm(prefix="chercheur") | |
7c596de2 | 100 | etablissement_form = EtablissementForm(prefix="etablissement") |
00755d9b | 101 | etablissement_autre_form = EtablissementAutreForm(prefix="etablissement_autre") |
7c596de2 | 102 | discipline_form = DisciplineForm(prefix="discipline") |
00755d9b AJ |
103 | publication1_form = PublicationForm(prefix="publication1") |
104 | publication2_form = PublicationForm(prefix="publication2") | |
105 | publication3_form = PublicationForm(prefix="publication3") | |
f810842d AJ |
106 | publication4_form = PublicationForm(prefix="publication4") |
107 | these_form = TheseForm(prefix="these") | |
932eef9a AJ |
108 | |
109 | variables = { 'personne_form': personne_form, | |
110 | 'chercheur_form': chercheur_form, | |
7c596de2 AJ |
111 | 'etablissement_form': etablissement_form, |
112 | 'discipline_form': discipline_form, | |
00755d9b AJ |
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, | |
f810842d | 118 | 'these_form': these_form, |
932eef9a AJ |
119 | } |
120 | ||
121 | return render_to_response ("chercheurs/inscription.html", \ | |
122 | Context (variables), | |
123 | context_instance = RequestContext(request)) | |
9af73c99 AJ |
124 | |
125 | ||
b3e1079e AJ |
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': | |
a955bdb8 | 131 | personne_form = PersonneEditForm(request.POST, prefix="personne", instance=chercheur.personne) |
f810842d | 132 | #chercheur_form = ChercheurForm (request.POST, prefix="chercheur", instance=chercheur) |
a955bdb8 AJ |
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) | |
f810842d | 140 | these_form = TheseForm(request.POST, prefix="these", instance=chercheur.these) |
a955bdb8 AJ |
141 | |
142 | ||
f810842d | 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() ): |
a955bdb8 | 144 | personne_form.save() |
f810842d | 145 | #chercheur_form.save() |
a955bdb8 AJ |
146 | discipline_form.save() |
147 | publication1_form.save() | |
148 | publication2_form.save() | |
149 | publication3_form.save() | |
150 | publication4_form.save() | |
f810842d | 151 | these_form.save() |
b3e1079e | 152 | else: |
a955bdb8 | 153 | personne_form = PersonneEditForm(prefix="personne", instance=chercheur.personne) |
f810842d | 154 | #chercheur_form = ChercheurForm (prefix="chercheur", instance=chercheur) |
a955bdb8 AJ |
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) | |
f810842d AJ |
161 | publication4_form = PublicationForm(prefix="publication4", instance=chercheur.publication4) |
162 | these_form = TheseForm(prefix="these", instance=chercheur.these) | |
b3e1079e AJ |
163 | |
164 | variables = { 'chercheur': chercheur, | |
165 | 'personne_form':personne_form, | |
f810842d | 166 | #'chercheur_form': chercheur_form, |
a955bdb8 AJ |
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, | |
f810842d | 174 | 'these_form': these_form, |
b3e1079e AJ |
175 | } |
176 | return render_to_response ("chercheurs/edit.html", \ | |
177 | Context (variables), | |
178 | context_instance = RequestContext(request)) | |
179 | ||
180 | ||
181 | ||
9af73c99 | 182 | def perso(request): |
588d6b93 | 183 | """Mock up de l'espace perso""" |
9af73c99 AJ |
184 | context_instance = RequestContext(request) |
185 | chercheur = context_instance['user_chercheur'] | |
588d6b93 | 186 | variables = { 'chercheur': chercheur, |
187 | } | |
188 | return render_to_response ("chercheurs/perso.html", \ | |
189 | Context (variables), | |
190 | context_instance = RequestContext(request)) | |
da091176 | 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)) |