retrait import inutile
[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 53 etablissement_form = EtablissementForm (request.POST, prefix="etablissement")
00755d9b 54 etablissement_autre_form = EtablissementAutreForm(request.POST, prefix="etablissement_autre")
7c596de2 55 discipline_form = DisciplineForm (request.POST, prefix="discipline")
00755d9b
AJ
56 publication1_form = PublicationForm (request.POST, prefix="publication1")
57 publication2_form = PublicationForm (request.POST, prefix="publication2")
58 publication3_form = PublicationForm (request.POST, prefix="publication3")
59 publication4_form = PublicationForm (request.POST, prefix="publication4")
7c596de2 60
932eef9a
AJ
61 if personne_form.is_valid():
62 if chercheur_form.is_valid():
932eef9a 63 c = chercheur_form.save(commit=False)
7c596de2
AJ
64
65 etablissement_form = EtablissementForm (request.POST, prefix="etablissement", instance=c)
66 discipline_form = DisciplineForm (request.POST, prefix="discipline", instance=c)
67
00755d9b
AJ
68 if etablissement_form.is_valid() and discipline_form.is_valid():
69 if publication1_form.is_valid():
70 pub = publication1_form.save()
71 c.publication1 = pub
72 if publication2_form.is_valid():
73 pub = publication2_form.save()
74 c.publication2 = pub
75 if publication3_form.is_valid():
76 pub = publication3_form.save()
77 c.publication3 = pub
78 if publication4_form.is_valid():
79 pub = publication4_form.save()
80 c.publication4 = pub
81 etablissement_form.save(commit=False)
82 etablissement_autre_form.save(commit=False)
7c596de2
AJ
83 discipline_form.save(commit=False)
84 p = personne_form.save()
85 c.personne = p
86 c.save()
932eef9a
AJ
87 else:
88 personne_form = PersonneForm(prefix="personne")
89 chercheur_form = ChercheurForm(prefix="chercheur")
7c596de2 90 etablissement_form = EtablissementForm(prefix="etablissement")
00755d9b 91 etablissement_autre_form = EtablissementAutreForm(prefix="etablissement_autre")
7c596de2 92 discipline_form = DisciplineForm(prefix="discipline")
00755d9b
AJ
93 publication1_form = PublicationForm(prefix="publication1")
94 publication2_form = PublicationForm(prefix="publication2")
95 publication3_form = PublicationForm(prefix="publication3")
96 publication4_form = PublicationForm(prefix="publication4")
932eef9a
AJ
97
98 variables = { 'personne_form': personne_form,
99 'chercheur_form': chercheur_form,
7c596de2
AJ
100 'etablissement_form': etablissement_form,
101 'discipline_form': discipline_form,
00755d9b
AJ
102 'etablissement_autre_form': etablissement_autre_form,
103 'publication1_form': publication1_form,
104 'publication2_form': publication2_form,
105 'publication3_form': publication3_form,
106 'publication4_form': publication4_form,
932eef9a
AJ
107 }
108
109 return render_to_response ("chercheurs/inscription.html", \
110 Context (variables),
111 context_instance = RequestContext(request))
9af73c99
AJ
112
113
b3e1079e
AJ
114def edit(request):
115 """Edition d'un chercheur"""
116 context_instance = RequestContext(request)
117 chercheur = context_instance['user_chercheur']
118 if request.method == 'POST':
119 personne_form = PersonneEditForm(request.POST, prefix="personne", instance=chercheur.personne)
120 personne_form.save()
121 else:
122 personne_form = PersonneEditForm(prefix="personne", instance=chercheur.personne)
123
124 variables = { 'chercheur': chercheur,
125 'personne_form':personne_form,
126 }
127 return render_to_response ("chercheurs/edit.html", \
128 Context (variables),
129 context_instance = RequestContext(request))
130
131
132
9af73c99 133def perso(request):
588d6b93 134 """Mock up de l'espace perso"""
9af73c99
AJ
135 context_instance = RequestContext(request)
136 chercheur = context_instance['user_chercheur']
588d6b93 137 variables = { 'chercheur': chercheur,
138 }
139 return render_to_response ("chercheurs/perso.html", \
140 Context (variables),
141 context_instance = RequestContext(request))
da091176 142
143def retrieve(request, id):
144 """Fiche du chercheur"""
145 chercheur = Chercheur.objects.get(id=id)
146 variables = { 'chercheur': chercheur,
147 }
148 return render_to_response ("chercheurs/retrieve.html", \
149 Context (variables),
150 context_instance = RequestContext(request))