1621: Région dans le listing d'offre d'emploi
[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 candidat = get_object_or_404(Candidat, id__in=request.GET.get('id'))
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 = Candidat.objects.filter(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
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,
64 instance=candidat, offre_emploi=offre_emploi)
65 piecesForm = CandidatPieceForm(request.POST, request.FILES,
66 instance=candidat)
67 print form.errors
68 if form.is_valid() and piecesForm.is_valid():
69 offre = form.save()
70 piecesForm.instance = offre
71 piecesForm.save()
72 messages.add_message(request, messages.SUCCESS,
73 "Votre application à l'appel d'offre d'emploi a \
74 été effectuée.")
75 return redirect("admin:recrutement_offreemploi_changelist")
76 else:
77 messages.add_message(request, messages.ERROR,
78 'Il y a des erreurs dans le formulaire.')
79 else:
80 form = PostulerOffreEmploiForm(instance=candidat,
81 offre_emploi=offre_emploi)
82 piecesForm = CandidatPieceForm(instance=candidat)
83
84 vars.update(dict(form=form, candidat=candidat, piecesForm=piecesForm, ))
85
86 return render_to_response('recrutement/postuler_appel_offre.html', vars,
87 RequestContext(request))