1 # -*- encoding: utf-8 -*-
3 from django
import forms
4 from django
.forms
import ModelForm
6 from auf
.django
.emploi
import forms
as emploi
7 from auf
.django
.emploi
import models
as emploi_models
9 from project
.recrutement
import models
as recr
11 ########################################################################
13 ########################################################################
14 class CandidatEvaluationForm(ModelForm
):
15 def __init__(self
, *args
, **kwargs
):
16 self
.candidat
= kwargs
.pop('candidat')
17 self
.evaluateur
= kwargs
.pop('evaluateur')
18 super(CandidatEvaluationForm
, self
).__init__(*args
, **kwargs
)
21 super(CandidatEvaluationForm
, self
).save()
24 fields
= ('note', 'commentaire')
25 model
= recr
.CandidatEvaluation
27 class EvaluateurForm(forms
.Form
):
28 evaluateurs
= forms
.ModelMultipleChoiceField(queryset
=
29 recr
.Evaluateur
.objects
.all(), required
=False)
32 def __init__(self
, *args
, **kwargs
):
33 self
.offres_emploi
= kwargs
.pop('offres_emploi')
34 evaluateurs
= [e
.id for e
in self
.get_evaluateurs()]
35 initial
= getattr(kwargs
, 'initial', {})
36 initial
['evaluateurs'] = evaluateurs
37 kwargs
['initial'] = initial
38 super(EvaluateurForm
, self
).__init__(*args
, **kwargs
)
41 def get_evaluateurs(self
):
42 return [e
.evaluateur
for e
in \
43 recr
.CandidatEvaluation
.objects
.filter(candidat__offre_emploi
=self
.offres_emploi
)]
46 candidats
= recr
.Candidat
.objects
.\
47 filter(offre_emploi
=self
.offres_emploi
)
49 anciens_evaluateurs
= self
.get_evaluateurs()
50 nouveaux__evaluateurs
= self
.cleaned_data
.get('evaluateurs', [])
52 # suppression des évaluations du type
53 evaluations
= recr
.CandidatEvaluation
.objects
.filter(candidat__offre_emploi
=self
.offres_emploi
)
55 if e
.evaluateur
not in nouveaux__evaluateurs
:
58 # on prépopulent les évaluations si elles ne l'ont pas déja été
59 for candidat
in candidats
:
60 for evaluateur
in self
.cleaned_data
.get('evaluateurs', []):
61 if evaluateur
not in anciens_evaluateurs
:
62 candidat_evaluation
= recr
.CandidatEvaluation()
63 candidat_evaluation
.candidat
= candidat
64 candidat_evaluation
.evaluateur
= evaluateur
65 candidat_evaluation
.save()
68 ########################################################################
70 ########################################################################
71 class CandidatPieceForm(emploi
.CandidatPieceForm
):
74 class PostulerOffreEmploiForm(emploi
.PostulerOffreEmploiForm
):
77 class OffreEmploiForm(ModelForm
):
78 nom
= forms
.CharField(label
='Intitulé du poste')
81 model
= emploi_models
.OffreEmploi
84 cleaned_data
= self
.cleaned_data
85 date_limite
= cleaned_data
.get("date_limite")
86 debut_affectation
= cleaned_data
.get("debut_affectation")
88 if date_limite
and debut_affectation
:
89 if date_limite
> debut_affectation
:
90 raise forms
.ValidationError("La date limite ne peut pas être \
91 supérieure à la date d'affection.")
94 ########################################################################
96 ########################################################################
97 class CandidatCourrielTemplateForm(ModelForm
):
98 def get_template(self
):
99 return self
.data
['template']
102 model
= recr
.CandidatCourriel
103 fields
= ('template', )
105 class CandidatCourrielForm(ModelForm
):
106 def __init__(self
, *args
, **kwargs
):
107 self
.candidats
= kwargs
.pop('candidats')
108 self
.template
= kwargs
.pop('template')
109 super(CandidatCourrielForm
, self
).__init__(*args
, **kwargs
)
112 super(CandidatCourrielForm
, self
).save()
115 model
= recr
.CandidatCourriel
116 fields
= ('sujet', 'plain_text', )