1548: Un évaluateur doit pouvoir éditer/évaluer un candidat qui lui est assigné
[auf_rh_dae.git] / project / recrutement / views.py
1 # -*- encoding: utf-8 -*-
2 from django.shortcuts import redirect, render_to_response, get_object_or_404
3 from django.http import HttpResponse
4 from django.contrib import messages
5 from django.template import Context, RequestContext
6 from django.shortcuts import render_to_response, redirect
7 from django.template import RequestContext
8 from django.contrib.auth.models import User
9
10 from forms import *
11 from models import *
12 from project.recrutement import models as recr
13
14 def index(request):
15 return render_to_response('recrutement/index.html', {},
16 RequestContext(request))
17
18 def evaluer_candidat(request):
19
20 candidat = get_object_or_404(Candidat, id__in=request.GET.get('id'))
21 if request.method == "POST":
22 candidat_evaluation = CandidatEvaluation()
23 candidat_evaluation.candidat = candidat
24 form = CandidatEvaluationForm(request.POST,
25 instance=candidat_evaluation, candidat=candidat)
26 if form.is_valid():
27 form.save()
28 messages.add_message(request, messages.SUCCESS,
29 "Le commentaire et la note ont été affectés \
30 au candidat.")
31 return redirect("admin:recrutement_candidat_changelist")
32 else:
33 form = CandidatEvaluationForm(candidat=candidat)
34
35 c = {'form' : form}
36 return render_to_response("recrutement/evaluer_candidat.html", Context(c),
37 context_instance = RequestContext(request))
38
39 def affecter_evaluateurs_candidats(request):
40 candidat_ids = request.GET.get('ids').split(',')
41 candidats = Candidat.objects.filter(id__in=candidat_ids)
42 if request.method == "POST":
43 form = EvaluateurForm(request.POST, candidats=candidats)
44 if form.is_valid():
45 form.save()
46 messages.add_message(request, messages.SUCCESS,
47 "Les évaluateurs ont été affectés aux candidats.")
48 return redirect("admin:recrutement_candidat_changelist")
49 else:
50 form = EvaluateurForm(candidats=candidats)
51
52 c = {'form' : form}
53 return render_to_response("recrutement/affecter_evaluateurs.html",
54 Context(c), context_instance = RequestContext(request))
55
56 def postuler_appel_offre(request):
57 vars = dict()
58 offre_emploi = get_object_or_404(OffreEmploi, id=request.GET.get('id'))
59 candidat = Candidat()
60 candidat.offre_emploi = offre_emploi
61
62 if request.method == "POST":
63 form = PostulerOffreEmploiForm(request.POST, request.FILES,
64 instance=candidat, offre_emploi=offre_emploi)
65 piecesForm = CandidatPieceForm(request.POST, request.FILES,
66 instance=candidat)
67 if form.is_valid() and piecesForm.is_valid():
68 form.save()
69 messages.add_message(request, messages.SUCCESS,
70 "Votre application à l'appel d'offre d'emploi a \
71 été effectuée.")
72 return redirect("admin:recrutement_offreemploi_changelist")
73 else:
74 form = PostulerOffreEmploiForm(instance=candidat,
75 offre_emploi=offre_emploi)
76 piecesForm = CandidatPieceForm(instance=candidat)
77
78 vars.update(dict(form=form, candidat=candidat, piecesForm=piecesForm, ))
79
80 return render_to_response('recrutement/postuler_appel_offre.html', vars,
81 RequestContext(request))