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
21 from project
.dae
.utils
import get_employe_from_user
as get_emp
23 ################################################################################
25 ################################################################################
26 class CandidatEvaluationForm(ModelForm
):
27 def __init__(self
, *args
, **kwargs
):
28 self
.candidat
= kwargs
.pop('candidat')
29 self
.evaluateur
= kwargs
.pop('evaluateur')
30 super(CandidatEvaluationForm
, self
).__init__(*args
, **kwargs
)
33 super(CandidatEvaluationForm
, self
).save()
36 fields
= ('note', 'commentaire')
37 model
= recr
.CandidatEvaluation
39 class EvaluateurForm(forms
.Form
):
40 evaluateurs
= forms
.ModelMultipleChoiceField(queryset
=
41 recr
.Evaluateur
.objects
.all())
43 def __init__(self
, *args
, **kwargs
):
44 self
.offres_emploi
= kwargs
.pop('offres_emploi')
45 super(EvaluateurForm
, self
).__init__(*args
, **kwargs
)
48 candidats
= recr
.Candidat
.objects
.\
49 filter(offre_emploi__in
=self
.offres_emploi
)
50 for candidat
in candidats
:
51 for evaluateur
in self
.cleaned_data
.get('evaluateurs', []):
52 candidat_evaluation
= recr
.CandidatEvaluation()
53 candidat_evaluation
.candidat
= candidat
54 candidat_evaluation
.evaluateur
= evaluateur
55 candidat_evaluation
.save()
58 ################################################################################
60 ################################################################################
61 class CandidatPieceForm(emploi
.CandidatPieceForm
):
64 class PostulerOffreEmploiForm(emploi
.PostulerOffreEmploiForm
):
67 class OffreEmploiForm(ModelForm
):
68 poste
= ModelChoiceField(queryset
=rh
.Poste
.objects
.all())
71 model
= recr
.OffreEmploi
73 def save(self
, *args
, **kwargs
):
74 kwargs2
= kwargs
.copy()
75 kwargs2
['commit'] = False
76 offre
= super(OffreEmploiForm
, self
).save(*args
, **kwargs2
)
77 offre
.poste
= self
.cleaned_data
.get("poste").id
78 offre
.poste_nom
= self
.cleaned_data
.get("poste").nom
79 if 'commit' not in kwargs
or kwargs
['commit']:
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.")
95 ################################################################################
97 ################################################################################
98 class CandidatCourrielTemplateForm(ModelForm
):
99 def get_template(self
):
100 return self
.data
['template']
103 model
= recr
.CandidatCourriel
104 fields
= ('template', )
106 class CandidatCourrielForm(ModelForm
):
107 def __init__(self
, *args
, **kwargs
):
108 self
.candidats
= kwargs
.pop('candidats')
109 self
.template
= kwargs
.pop('template')
110 super(CandidatCourrielForm
, self
).__init__(*args
, **kwargs
)
113 super(CandidatCourrielForm
, self
).save()
116 model
= recr
.CandidatCourriel
117 fields
= ('sujet', 'plain_text', 'html')