294013e5569446547d3a7a47dfea521a9d864d5b
1 # -*- encoding: utf-8 -*-
4 from django
import forms
5 from django
.contrib
import admin
6 from django
.forms
.models
import inlineformset_factory
7 from datetime
import timedelta
8 from django
.forms
.widgets
import CheckboxSelectMultiple
9 from django
.contrib
.admin
import widgets
as admin_widgets
10 from form_utils
.forms
import BetterModelForm
11 from django
.forms
import ModelForm
, ModelChoiceField
, HiddenInput
, CharField
12 from django
.forms
.models
import BaseInlineFormSet
13 from django
.core
.mail
import send_mail
15 from tinymce
.widgets
import TinyMCE
16 from captcha
.fields
import CaptchaField
18 from recrutement
import models
as recr
19 from auf
.django
.emploi
import forms
as emploi
20 from project
.rh
import models
as rh
22 ################################################################################
24 ################################################################################
25 class CandidatEvaluationForm(ModelForm
):
26 def __init__(self
, *args
, **kwargs
):
27 self
.candidat
= kwargs
.pop('candidat')
28 self
.evaluateur
= kwargs
.pop('evaluateur')
29 super(CandidatEvaluationForm
, self
).__init__(*args
, **kwargs
)
32 super(CandidatEvaluationForm
, self
).save()
35 fields
= ('note', 'commentaire')
36 model
= recr
.CandidatEvaluation
38 class EvaluateurForm(forms
.Form
):
39 evaluateurs
= forms
.ModelMultipleChoiceField(queryset
=
40 recr
.Evaluateur
.objects
.all())
42 def __init__(self
, *args
, **kwargs
):
43 self
.offres_emploi
= kwargs
.pop('offres_emploi')
44 super(EvaluateurForm
, self
).__init__(*args
, **kwargs
)
47 candidats
= recr
.Candidat
.objects
.\
48 filter(offre_emploi__in
=self
.offres_emploi
)
49 for candidat
in candidats
:
50 for evaluateur
in self
.cleaned_data
.get('evaluateurs', []):
51 candidat_evaluation
= recr
.CandidatEvaluation()
52 candidat_evaluation
.candidat
= candidat
53 candidat_evaluation
.evaluateur
= evaluateur
54 candidat_evaluation
.save()
57 ################################################################################
59 ################################################################################
60 class CandidatPieceForm(emploi
.CandidatPieceForm
):
63 class PostulerOffreEmploiForm(emploi
.PostulerOffreEmploiForm
):
66 class OffreEmploiForm(ModelForm
):
67 poste
= ModelChoiceField(queryset
=rh
.Poste
.objects
.all())
70 model
= recr
.OffreEmploi
72 def save(self
, *args
, **kwargs
):
73 kwargs2
= kwargs
.copy()
74 kwargs2
['commit'] = False
75 offre
= super(OffreEmploiForm
, self
).save(*args
, **kwargs2
)
76 offre
.poste
= self
.cleaned_data
.get("poste").id
77 offre
.poste_nom
= self
.cleaned_data
.get("poste").nom
78 if 'commit' not in kwargs
or kwargs
['commit']:
83 cleaned_data
= self
.cleaned_data
84 date_limite
= cleaned_data
.get("date_limite")
85 debut_affectation
= cleaned_data
.get("debut_affectation")
87 if date_limite
and debut_affectation
:
88 if date_limite
> debut_affectation
:
89 raise forms
.ValidationError("La date limite ne peut pas être \
90 supérieure à la date d'affection.")
92 """if date_limite < datetime.date.today() or \
93 debut_affectation < datetime.date.today():
94 raise forms.ValidationError("La date limite et/ou la date \
95 d'affection doivent être supérieures à la date d'aujourdhui.")
99 ################################################################################
101 ################################################################################
102 class CandidatCourrielTemplateForm(ModelForm
):
103 def get_template(self
):
104 return self
.data
['template']
107 model
= recr
.CandidatCourriel
108 fields
= ('template', )
110 class CandidatCourrielForm(ModelForm
):
111 def __init__(self
, *args
, **kwargs
):
112 self
.candidats
= kwargs
.pop('candidats')
113 self
.template
= kwargs
.pop('template')
114 super(CandidatCourrielForm
, self
).__init__(*args
, **kwargs
)
117 super(CandidatCourrielForm
, self
).save()
120 model
= recr
.CandidatCourriel
121 fields
= ('sujet', 'plain_text', 'html')