Merge branch 'dev' into test
[auf_rh_dae.git] / project / recrutement / forms.py
CommitLineData
83252c4c 1# -*- encoding: utf-8 -*-
2
3import os
4from django import forms
5from django.contrib import admin
6from django.forms.models import inlineformset_factory
ee42ad96 7from datetime import timedelta
8from django.forms.widgets import CheckboxSelectMultiple
9from django.contrib.admin import widgets as admin_widgets
8ea41642 10from form_utils.forms import BetterModelForm
e2968e84 11from django.forms import ModelForm, ModelChoiceField, HiddenInput, CharField
2b3edf33 12from django.forms.models import BaseInlineFormSet
240940e1 13from django.core.mail import send_mail
ee42ad96 14
ec517164 15from tinymce.widgets import TinyMCE
86caaf03 16from captcha.fields import CaptchaField
ec517164 17
18from recrutement import models as recr
240940e1 19from auf.django.emploi import forms as emploi
e2968e84 20from project.rh import models as rh
240940e1 21
83252c4c 22################################################################################
23# EVALUATION
24################################################################################
25class CandidatEvaluationForm(ModelForm):
26 def __init__(self, *args, **kwargs):
27 self.candidat = kwargs.pop('candidat')
e34a2ae0 28 self.evaluateur = kwargs.pop('evaluateur')
83252c4c 29 super(CandidatEvaluationForm, self).__init__(*args, **kwargs)
30
31 def save(self):
32 super(CandidatEvaluationForm, self).save()
33
34 class Meta:
e34a2ae0 35 fields = ('note', 'commentaire')
2b3edf33 36 model = recr.CandidatEvaluation
83252c4c 37
38class EvaluateurForm(forms.Form):
8ea41642 39 evaluateurs = forms.ModelMultipleChoiceField(queryset=
27c81d11 40 recr.Evaluateur.objects.all())
83252c4c 41
42 def __init__(self, *args, **kwargs):
540dfae4 43 self.offres_emploi = kwargs.pop('offres_emploi')
83252c4c 44 super(EvaluateurForm, self).__init__(*args, **kwargs)
45
46 def save(self):
540dfae4
NBV
47 candidats = recr.Candidat.objects.\
48 filter(offre_emploi__in=self.offres_emploi)
540dfae4 49 for candidat in candidats:
21b02da5 50 for evaluateur in self.cleaned_data.get('evaluateurs', []):
c4874d66 51 candidat_evaluation = recr.CandidatEvaluation()
21b02da5
NBV
52 candidat_evaluation.candidat = candidat
53 candidat_evaluation.evaluateur = evaluateur
c4874d66 54 candidat_evaluation.save()
540dfae4 55
83252c4c 56
57################################################################################
58# OFFRE EMPLOI
59################################################################################
240940e1
NBV
60class CandidatPieceForm(emploi.CandidatPieceForm):
61 pass
86caaf03 62
240940e1
NBV
63class PostulerOffreEmploiForm(emploi.PostulerOffreEmploiForm):
64 pass
ec517164 65
a084e988 66class OffreEmploiForm(ModelForm):
e2968e84
NBV
67 poste = ModelChoiceField(queryset=rh.Poste.objects.all())
68
a084e988
NBV
69 class Meta:
70 model = recr.OffreEmploi
71
e2968e84
NBV
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")
77 offre.poste_nom = self.cleaned_data.get("poste").nom
78 if 'commit' not in kwargs or kwargs['commit']:
79 offre.save()
80 return offre
81
540dfae4
NBV
82 def clean(self):
83 cleaned_data = self.cleaned_data
84 date_limite = cleaned_data.get("date_limite")
85 debut_affectation = cleaned_data.get("debut_affectation")
86
87 if date_limite and debut_affectation:
88 if date_limite > debut_affectation:
1dd2d51f 89 raise forms.ValidationError("La date limite ne peut pas être \
a084e988
NBV
90 supérieure à la date d'affection.")
91
e2968e84
NBV
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.")
96 """
540dfae4 97 return cleaned_data
a084e988 98
d84c3a68 99################################################################################
100# TEMPLATE COURRIEL
101################################################################################
32834000
NBV
102class CandidatCourrielTemplateForm(ModelForm):
103 def get_template(self):
104 return self.data['template']
d84c3a68 105
32834000
NBV
106 class Meta:
107 model = recr.CandidatCourriel
108 fields = ('template', )
109
110class CandidatCourrielForm(ModelForm):
d84c3a68 111 def __init__(self, *args, **kwargs):
112 self.candidats = kwargs.pop('candidats')
32834000 113 self.template = kwargs.pop('template')
d84c3a68 114 super(CandidatCourrielForm, self).__init__(*args, **kwargs)
115
116 def save(self):
117 super(CandidatCourrielForm, self).save()
118
119 class Meta:
120 model = recr.CandidatCourriel
32834000 121 fields = ('sujet', 'plain_text', 'html')
d84c3a68 122