1591: Créer une app formulaire-recrutement qui permettra à un candidat de postuler...
[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 offre_emploi = get_object_or_404(OffreEmploi, id=request.GET.get('id'))
57 candidat = Candidat()
58 candidat.offre_emploi = offre_emploi
59 if request.method == "POST":
60 form = PostulerOffreEmploiForm(request.POST, instance=candidat,
61 offre_emploi=offre_emploi)
62 if form.is_valid():
63 form.save()
64 messages.add_message(request, messages.SUCCESS,
65 "Votre application à l'appel d'offre d'emploi a \
66 été effectuée.")
67 return redirect("admin:recrutement_offreemploi_changelist")
68 else:
69 form = PostulerOffreEmploiForm(offre_emploi=offre_emploi)
70
71 c = {'form' : form}
72 return render_to_response("recrutement/postuler_appel_offre.html",
73 Context(c), context_instance = RequestContext(request))