Pièces jointes et 1852:Changer les adresse hardcodé dans l'API
[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
30945e50 21from project.dae.utils import get_employe_from_user as get_emp
240940e1 22
83252c4c 23################################################################################
24# EVALUATION
25################################################################################
26class CandidatEvaluationForm(ModelForm):
27 def __init__(self, *args, **kwargs):
28 self.candidat = kwargs.pop('candidat')
e34a2ae0 29 self.evaluateur = kwargs.pop('evaluateur')
83252c4c 30 super(CandidatEvaluationForm, self).__init__(*args, **kwargs)
31
32 def save(self):
33 super(CandidatEvaluationForm, self).save()
34
35 class Meta:
e34a2ae0 36 fields = ('note', 'commentaire')
2b3edf33 37 model = recr.CandidatEvaluation
83252c4c 38
39class EvaluateurForm(forms.Form):
8ea41642 40 evaluateurs = forms.ModelMultipleChoiceField(queryset=
27c81d11 41 recr.Evaluateur.objects.all())
83252c4c 42
43 def __init__(self, *args, **kwargs):
540dfae4 44 self.offres_emploi = kwargs.pop('offres_emploi')
83252c4c 45 super(EvaluateurForm, self).__init__(*args, **kwargs)
46
47 def save(self):
540dfae4
NBV
48 candidats = recr.Candidat.objects.\
49 filter(offre_emploi__in=self.offres_emploi)
540dfae4 50 for candidat in candidats:
21b02da5 51 for evaluateur in self.cleaned_data.get('evaluateurs', []):
c4874d66 52 candidat_evaluation = recr.CandidatEvaluation()
21b02da5
NBV
53 candidat_evaluation.candidat = candidat
54 candidat_evaluation.evaluateur = evaluateur
c4874d66 55 candidat_evaluation.save()
540dfae4 56
83252c4c 57
58################################################################################
59# OFFRE EMPLOI
60################################################################################
240940e1
NBV
61class CandidatPieceForm(emploi.CandidatPieceForm):
62 pass
86caaf03 63
240940e1
NBV
64class PostulerOffreEmploiForm(emploi.PostulerOffreEmploiForm):
65 pass
ec517164 66
a084e988 67class OffreEmploiForm(ModelForm):
e2968e84
NBV
68 poste = ModelChoiceField(queryset=rh.Poste.objects.all())
69
a084e988
NBV
70 class Meta:
71 model = recr.OffreEmploi
72
e2968e84
NBV
73 def save(self, *args, **kwargs):
74 kwargs2 = kwargs.copy()
75 kwargs2['commit'] = False
76 offre = super(OffreEmploiForm, self).save(*args, **kwargs2)
43198a9f 77 offre.poste = self.cleaned_data.get("poste").id
e2968e84
NBV
78 offre.poste_nom = self.cleaned_data.get("poste").nom
79 if 'commit' not in kwargs or kwargs['commit']:
80 offre.save()
81 return offre
82
540dfae4
NBV
83 def clean(self):
84 cleaned_data = self.cleaned_data
85 date_limite = cleaned_data.get("date_limite")
86 debut_affectation = cleaned_data.get("debut_affectation")
87
88 if date_limite and debut_affectation:
89 if date_limite > debut_affectation:
1dd2d51f 90 raise forms.ValidationError("La date limite ne peut pas être \
a084e988
NBV
91 supérieure à la date d'affection.")
92
540dfae4 93 return cleaned_data
a084e988 94
d84c3a68 95################################################################################
96# TEMPLATE COURRIEL
97################################################################################
32834000
NBV
98class CandidatCourrielTemplateForm(ModelForm):
99 def get_template(self):
100 return self.data['template']
d84c3a68 101
32834000
NBV
102 class Meta:
103 model = recr.CandidatCourriel
104 fields = ('template', )
105
106class CandidatCourrielForm(ModelForm):
d84c3a68 107 def __init__(self, *args, **kwargs):
108 self.candidats = kwargs.pop('candidats')
32834000 109 self.template = kwargs.pop('template')
d84c3a68 110 super(CandidatCourrielForm, self).__init__(*args, **kwargs)
111
112 def save(self):
113 super(CandidatCourrielForm, self).save()
114
115 class Meta:
116 model = recr.CandidatCourriel
32834000 117 fields = ('sujet', 'plain_text', 'html')
d84c3a68 118