1593: Ajouter les pièces jointes pour la postulation.
[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
9 from forms import *
10 from models import *
11 from project.recrutement import models as recr
12
13 def index(request):
14 return render_to_response('recrutement/index.html', {},
15 RequestContext(request))
16
17 def evaluer_candidat(request):
18 candidat = get_object_or_404(Candidat, id__in=request.GET.get('id'))
19
20 if request.method == "POST":
21 candidat_evaluation = CandidatEvaluation()
22 candidat_evaluation.candidat = candidat
23 form = CandidatEvaluationForm(request.POST,
24 instance=candidat_evaluation, candidat=candidat)
25 if form.is_valid():
26 form.save()
27 messages.add_message(request, messages.SUCCESS,
28 "Le commentaire et la note ont été affectés \
29 au candidat.")
30 return redirect("admin:recrutement_candidat_changelist")
31 else:
32 form = CandidatEvaluationForm(candidat=candidat)
33
34 c = {'form' : form}
35 return render_to_response("recrutement/evaluer_candidat.html", Context(c),
36 context_instance = RequestContext(request))
37
38 def affecter_evaluateurs_candidats(request):
39 candidat_ids = request.GET.get('ids').split(',')
40 candidats = get_object_or_404(Candidat, id__in=candidat_ids)
41 if request.method == "POST":
42 form = EvaluateurForm(request.POST, candidats=candidats)
43 if form.is_valid():
44 form.save()
45 messages.add_message(request, messages.SUCCESS,
46 "Les évaluateurs ont été affectés aux candidats.")
47 return redirect("admin:recrutement_candidat_changelist")
48 else:
49 form = EvaluateurForm(candidats=candidats)
50
51 c = {'form' : form}
52 return render_to_response("recrutement/affecter_evaluateurs.html",
53 Context(c), context_instance = RequestContext(request))
54
55 def postuler_appel_offre(request):
56 vars = dict()
57 offre_emploi = get_object_or_404(OffreEmploi, id=request.GET.get('id'))
58 candidat = Candidat()
59 candidat.offre_emploi = offre_emploi
60
61 if request.method == "POST":
62 form = PostulerOffreEmploiForm(request.POST, request.FILES, instance=candidat, offre_emploi=offre_emploi)
63 piecesForm = CandidatPieceForm(request.POST, request.FILES, instance=candidat)
64 #import pdb;pdb.set_trace()
65 if form.is_valid() and piecesForm.is_valid():
66 form.save()
67 messages.add_message(request, messages.SUCCESS,
68 "Votre application à l'appel d'offre d'emploi a \
69 été effectuée.")
70 return redirect("admin:recrutement_offreemploi_changelist")
71 else:
72 form = PostulerOffreEmploiForm(instance=candidat, offre_emploi=offre_emploi)
73 piecesForm = CandidatPieceForm(instance=candidat)
74
75 vars.update(dict(form=form, candidat=candidat, piecesForm=piecesForm, ))
76
77 return render_to_response('recrutement/postuler_appel_offre.html', vars,
78 RequestContext(request))