1642: Ajout de pièces jointes
[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 afficher_candidat(request):
19 candidat = get_object_or_404(Candidat, id=request.GET.get('id'))
20 pieces_jointes = CandidatPiece.objects.get(candidat=candidat)
21 #import pdb;pdb.set_trace()
22 var = {'candidat': candidat,
23 'pieces_jointes': pieces_jointes}
24 return render_to_response("recrutement/afficher_candidat.html", var,
25 RequestContext(request))
26
27 def evaluer_candidat(request):
28 candidat = get_object_or_404(Candidat, id=request.GET.get('id'))
29
30 try:
31 evaluateur = UserProfile.objects.get(user=request.user)
32 except UserProfile.DoesNotExist:
33 messages.add_message(request, messages.ERROR,
34 "Vous ne pouvez pas évaluer ce candidat.")
35 return redirect("admin:recrutement_candidat_changelist")
36
37 if request.method == "POST":
38 candidat_evaluation = CandidatEvaluation()
39 candidat_evaluation.candidat = candidat
40 candidat_evaluation.evaluateur = evaluateur
41 form = CandidatEvaluationForm(request.POST,
42 instance=candidat_evaluation, candidat=candidat,
43 evaluateur=evaluateur)
44 if form.is_valid():
45 form.save()
46 messages.add_message(request, messages.SUCCESS,
47 "Le commentaire et la note ont été affectés \
48 au candidat.")
49 return redirect("admin:recrutement_candidat_changelist")
50 else:
51 form = CandidatEvaluationForm(candidat=candidat, evaluateur=evaluateur)
52
53 c = {'form' : form}
54 return render_to_response("recrutement/evaluer_candidat.html", Context(c),
55 context_instance = RequestContext(request))
56
57 def affecter_evaluateurs_candidats(request):
58 candidat_ids = request.GET.get('ids').split(',')
59 candidats = Candidat.objects.filter(id__in=candidat_ids)
60 if request.method == "POST":
61 form = EvaluateurForm(request.POST, candidats=candidats)
62 if form.is_valid():
63 form.save()
64 messages.add_message(request, messages.SUCCESS,
65 "Les évaluateurs ont été affectés aux candidats.")
66 return redirect("admin:recrutement_candidat_changelist")
67 else:
68 form = EvaluateurForm(candidats=candidats)
69
70 c = {'form' : form}
71 return render_to_response("recrutement/affecter_evaluateurs.html",
72 Context(c), context_instance = RequestContext(request))
73
74 def postuler_appel_offre(request):
75
76 vars = dict()
77 offre_emploi = get_object_or_404(OffreEmploi, id=request.GET.get('id'))
78 candidat = Candidat()
79 candidat.offre_emploi = offre_emploi
80
81 if request.method == "POST":
82 form = PostulerOffreEmploiForm(request.POST,
83 instance=candidat, offre_emploi=offre_emploi)
84 piecesForm = CandidatPieceForm(request.POST, request.FILES,
85 instance=candidat)
86 print form.errors
87 if form.is_valid() and piecesForm.is_valid():
88 offre = form.save()
89 piecesForm.instance = offre
90 piecesForm.save()
91 messages.add_message(request, messages.SUCCESS,
92 "Votre application à l'appel d'offre d'emploi a \
93 été effectuée.")
94 return redirect("admin:recrutement_offreemploi_changelist")
95 else:
96 messages.add_message(request, messages.ERROR,
97 'Il y a des erreurs dans le formulaire.')
98 else:
99 form = PostulerOffreEmploiForm(instance=candidat,
100 offre_emploi=offre_emploi)
101 piecesForm = CandidatPieceForm(instance=candidat)
102
103 vars.update(dict(form=form, candidat=candidat, piecesForm=piecesForm, ))
104
105 return render_to_response('recrutement/postuler_appel_offre.html', vars,
106 RequestContext(request))