778e72c90b056ecf2a16781fc84bf4700e804f48
[auf_rh_dae.git] / project / recrutement / forms.py
1 # -*- encoding: utf-8 -*-
2
3 import os
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
14
15 from datamaster_modeles.models import Employe, Implantation, Region
16 from tinymce.widgets import TinyMCE
17 from captcha.fields import CaptchaField
18
19 from recrutement import models as recr
20 from auf.django.emploi import forms as emploi
21 from project.rh import models as rh
22 from project.dae.utils import get_employe_from_user as get_emp
23
24 ################################################################################
25 # EVALUATION
26 ################################################################################
27 class CandidatEvaluationForm(ModelForm):
28 def __init__(self, *args, **kwargs):
29 self.candidat = kwargs.pop('candidat')
30 self.evaluateur = kwargs.pop('evaluateur')
31 super(CandidatEvaluationForm, self).__init__(*args, **kwargs)
32
33 def save(self):
34 super(CandidatEvaluationForm, self).save()
35
36 class Meta:
37 fields = ('note', 'commentaire')
38 model = recr.CandidatEvaluation
39
40 class EvaluateurForm(forms.Form):
41 evaluateurs = forms.ModelMultipleChoiceField(queryset=
42 recr.Evaluateur.objects.all())
43
44 def __init__(self, *args, **kwargs):
45 self.offres_emploi = kwargs.pop('offres_emploi')
46 super(EvaluateurForm, self).__init__(*args, **kwargs)
47
48 def save(self):
49 candidats = recr.Candidat.objects.\
50 filter(offre_emploi__in=self.offres_emploi)
51 for candidat in candidats:
52 for evaluateur in self.cleaned_data.get('evaluateurs', []):
53 candidat_evaluation = recr.CandidatEvaluation()
54 candidat_evaluation.candidat = candidat
55 candidat_evaluation.evaluateur = evaluateur
56 candidat_evaluation.save()
57
58
59 ################################################################################
60 # OFFRE EMPLOI
61 ################################################################################
62 class CandidatPieceForm(emploi.CandidatPieceForm):
63 pass
64
65 class PostulerOffreEmploiForm(emploi.PostulerOffreEmploiForm):
66 pass
67
68 class OffreEmploiForm(ModelForm):
69 poste = ModelChoiceField(queryset=rh.Poste.objects.all())
70
71 class Meta:
72 model = recr.OffreEmploi
73
74 def __init__(self, *args, **kwargs):
75 super(OffreEmploiForm, self).__init__(*args, **kwargs)
76
77 def save(self, *args, **kwargs):
78 kwargs2 = kwargs.copy()
79 kwargs2['commit'] = False
80 offre = super(OffreEmploiForm, self).save(*args, **kwargs2)
81 offre.poste = self.cleaned_data.get("poste").id
82 offre.poste_nom = self.cleaned_data.get("poste").nom
83 if 'commit' not in kwargs or kwargs['commit']:
84 offre.save()
85 return offre
86
87 def clean(self):
88 cleaned_data = self.cleaned_data
89 date_limite = cleaned_data.get("date_limite")
90 debut_affectation = cleaned_data.get("debut_affectation")
91
92 if date_limite and debut_affectation:
93 if date_limite > debut_affectation:
94 raise forms.ValidationError("La date limite ne peut pas être \
95 supérieure à la date d'affection.")
96
97 return cleaned_data
98
99 ################################################################################
100 # TEMPLATE COURRIEL
101 ################################################################################
102 class CandidatCourrielTemplateForm(ModelForm):
103 def get_template(self):
104 return self.data['template']
105
106 class Meta:
107 model = recr.CandidatCourriel
108 fields = ('template', )
109
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)
115
116 def save(self):
117 super(CandidatCourrielForm, self).save()
118
119 class Meta:
120 model = recr.CandidatCourriel
121 fields = ('sujet', 'plain_text', 'html')
122