retrait import inutile
[auf_savoirs_en_partage_django.git] / auf_savoirs_en_partage / chercheurs / views.py
1 # -*- encoding: utf-8 -*-
2 from django.shortcuts import render_to_response
3 from django.template import Context, RequestContext
4 from forms import *
5
6 from auf_references_client.models import Discipline, TypeImplantation
7 from models import Personne, Utilisateur
8
9 from django.contrib.auth.decorators import login_required
10
11 def 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
34 def repertoire(request):
35 """Mock up du répertoire"""
36
37 chercheurs = chercheur_queryset (request)
38 repertoire_form = RepertoireSearchForm (request.GET)
39
40 nb_chercheurs = chercheurs.count()
41 variables = { 'chercheurs': chercheurs,
42 'nb_chercheurs': nb_chercheurs,
43 'repertoire_form': repertoire_form,
44 }
45 return render_to_response ("chercheurs/repertoire.html", \
46 Context (variables),
47 context_instance = RequestContext(request))
48
49 def inscription(request):
50 if request.method == 'POST':
51 personne_form = PersonneForm (request.POST, prefix="personne")
52 chercheur_form = ChercheurForm (request.POST, prefix="chercheur")
53 etablissement_form = EtablissementForm (request.POST, prefix="etablissement")
54 etablissement_autre_form = EtablissementAutreForm(request.POST, prefix="etablissement_autre")
55 discipline_form = DisciplineForm (request.POST, prefix="discipline")
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")
60
61 if personne_form.is_valid():
62 if chercheur_form.is_valid():
63 c = chercheur_form.save(commit=False)
64
65 etablissement_form = EtablissementForm (request.POST, prefix="etablissement", instance=c)
66 discipline_form = DisciplineForm (request.POST, prefix="discipline", instance=c)
67
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)
83 discipline_form.save(commit=False)
84 p = personne_form.save()
85 c.personne = p
86 c.save()
87 else:
88 personne_form = PersonneForm(prefix="personne")
89 chercheur_form = ChercheurForm(prefix="chercheur")
90 etablissement_form = EtablissementForm(prefix="etablissement")
91 etablissement_autre_form = EtablissementAutreForm(prefix="etablissement_autre")
92 discipline_form = DisciplineForm(prefix="discipline")
93 publication1_form = PublicationForm(prefix="publication1")
94 publication2_form = PublicationForm(prefix="publication2")
95 publication3_form = PublicationForm(prefix="publication3")
96 publication4_form = PublicationForm(prefix="publication4")
97
98 variables = { 'personne_form': personne_form,
99 'chercheur_form': chercheur_form,
100 'etablissement_form': etablissement_form,
101 'discipline_form': discipline_form,
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,
107 }
108
109 return render_to_response ("chercheurs/inscription.html", \
110 Context (variables),
111 context_instance = RequestContext(request))
112
113
114 def 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
133 def perso(request):
134 """Mock up de l'espace perso"""
135 context_instance = RequestContext(request)
136 chercheur = context_instance['user_chercheur']
137 variables = { 'chercheur': chercheur,
138 }
139 return render_to_response ("chercheurs/perso.html", \
140 Context (variables),
141 context_instance = RequestContext(request))
142
143 def 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))