chercheur model avance
[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
8
9 def repertoire(request):
10 """Mock up du répertoire"""
11 chercheurs = Chercheur.objects.all()
12 nb_chercheurs = chercheurs.count()
13 variables = { 'chercheurs': chercheurs,
14 'nb_chercheurs': nb_chercheurs,
15 }
16 return render_to_response ("chercheurs/repertoire.html", \
17 Context (variables),
18 context_instance = RequestContext(request))
19
20 def inscription(request):
21 if request.method == 'POST':
22 personne_form = PersonneForm (request.POST, prefix="personne")
23 chercheur_form = ChercheurForm (request.POST, prefix="chercheur")
24 etablissement_form = EtablissementForm (request.POST, prefix="etablissement")
25 discipline_form = DisciplineForm (request.POST, prefix="discipline")
26
27 if personne_form.is_valid():
28 if chercheur_form.is_valid():
29 c = chercheur_form.save(commit=False)
30
31 etablissement_form = EtablissementForm (request.POST, prefix="etablissement", instance=c)
32 discipline_form = DisciplineForm (request.POST, prefix="discipline", instance=c)
33
34 if etablissement_form.is_valid() and discipline_form.is_valid():
35 etablissement_form.save(commit=False)
36 discipline_form.save(commit=False)
37 p = personne_form.save()
38 c.personne = p
39 c.save()
40 else:
41 personne_form = PersonneForm(prefix="personne")
42 chercheur_form = ChercheurForm(prefix="chercheur")
43 etablissement_form = EtablissementForm(prefix="etablissement")
44 discipline_form = DisciplineForm(prefix="discipline")
45
46 variables = { 'personne_form': personne_form,
47 'chercheur_form': chercheur_form,
48 'etablissement_form': etablissement_form,
49 'discipline_form': discipline_form,
50 }
51
52 return render_to_response ("chercheurs/inscription.html", \
53 Context (variables),
54 context_instance = RequestContext(request))
55
56 def perso(request, id):
57 """Mock up de l'espace perso"""
58 chercheur = Chercheur.objects.get(id=id)
59 variables = { 'chercheur': chercheur,
60 }
61 return render_to_response ("chercheurs/perso.html", \
62 Context (variables),
63 context_instance = RequestContext(request))
64
65 def retrieve(request, id):
66 """Fiche du chercheur"""
67 chercheur = Chercheur.objects.get(id=id)
68 variables = { 'chercheur': chercheur,
69 }
70 return render_to_response ("chercheurs/retrieve.html", \
71 Context (variables),
72 context_instance = RequestContext(request))