Retrait des modules references et datamaster dans INSTALLED_APPS pour eviter que...
[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
7from models import Personne
8
13146d99
AJ
9
10def chercheur_queryset (request):
11 list = Chercheur.objects.order_by("id")
12 pays = ""
13
14 simpleForm = RepertoireSearchForm (request.GET)
15 if simpleForm.is_valid ():
16 pays = simpleForm.cleaned_data["pays"]
17 if pays:
18 list = list.filter (pays = pays.pk)
19 fonction = simpleForm.cleaned_data["fonction"]
20 if fonction:
21 list = list.filter (fonction = fonction)
22 genre = simpleForm.cleaned_data["genre"]
23 if genre:
24 list = list.filter (personne__genre=genre)
25 discipline = simpleForm.cleaned_data["discipline"]
26 if discipline:
27 list = list.filter (discipline=discipline)
28 mots_cles = simpleForm.cleaned_data["mots_cles"]
29 if mots_cles:
30 list = list.filter (personne__nom__icontains=mots_cles)
31 return list
32
588d6b93 33def repertoire(request):
34 """Mock up du répertoire"""
13146d99
AJ
35
36 chercheurs = chercheur_queryset (request)
37 repertoire_form = RepertoireSearchForm (request.GET)
38
9f7c169e 39 nb_chercheurs = chercheurs.count()
588d6b93 40 variables = { 'chercheurs': chercheurs,
9f7c169e 41 'nb_chercheurs': nb_chercheurs,
13146d99 42 'repertoire_form': repertoire_form,
588d6b93 43 }
44 return render_to_response ("chercheurs/repertoire.html", \
45 Context (variables),
46 context_instance = RequestContext(request))
47
932eef9a
AJ
48def inscription(request):
49 if request.method == 'POST':
50 personne_form = PersonneForm (request.POST, prefix="personne")
51 chercheur_form = ChercheurForm (request.POST, prefix="chercheur")
7c596de2
AJ
52 etablissement_form = EtablissementForm (request.POST, prefix="etablissement")
53 discipline_form = DisciplineForm (request.POST, prefix="discipline")
54
932eef9a
AJ
55 if personne_form.is_valid():
56 if chercheur_form.is_valid():
932eef9a 57 c = chercheur_form.save(commit=False)
7c596de2
AJ
58
59 etablissement_form = EtablissementForm (request.POST, prefix="etablissement", instance=c)
60 discipline_form = DisciplineForm (request.POST, prefix="discipline", instance=c)
61
62 if etablissement_form.is_valid() and discipline_form.is_valid():
63 etablissement_form.save(commit=False)
64 discipline_form.save(commit=False)
65 p = personne_form.save()
66 c.personne = p
67 c.save()
932eef9a
AJ
68 else:
69 personne_form = PersonneForm(prefix="personne")
70 chercheur_form = ChercheurForm(prefix="chercheur")
7c596de2
AJ
71 etablissement_form = EtablissementForm(prefix="etablissement")
72 discipline_form = DisciplineForm(prefix="discipline")
932eef9a
AJ
73
74 variables = { 'personne_form': personne_form,
75 'chercheur_form': chercheur_form,
7c596de2
AJ
76 'etablissement_form': etablissement_form,
77 'discipline_form': discipline_form,
932eef9a
AJ
78 }
79
80 return render_to_response ("chercheurs/inscription.html", \
81 Context (variables),
82 context_instance = RequestContext(request))
588d6b93 83
da091176 84def perso(request, id):
588d6b93 85 """Mock up de l'espace perso"""
da091176 86 chercheur = Chercheur.objects.get(id=id)
588d6b93 87 variables = { 'chercheur': chercheur,
88 }
89 return render_to_response ("chercheurs/perso.html", \
90 Context (variables),
91 context_instance = RequestContext(request))
da091176 92
93def retrieve(request, id):
94 """Fiche du chercheur"""
95 chercheur = Chercheur.objects.get(id=id)
96 variables = { 'chercheur': chercheur,
97 }
98 return render_to_response ("chercheurs/retrieve.html", \
99 Context (variables),
100 context_instance = RequestContext(request))