1966: Modification de Offre d'emploi (visualisation)
[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
d333c690 15from datamaster_modeles.models import Employe, Implantation, Region
ec517164 16from tinymce.widgets import TinyMCE
86caaf03 17from captcha.fields import CaptchaField
ec517164 18
19from recrutement import models as recr
240940e1 20from auf.django.emploi import forms as emploi
e2968e84 21from project.rh import models as rh
30945e50 22from project.dae.utils import get_employe_from_user as get_emp
240940e1 23
83252c4c 24################################################################################
25# EVALUATION
26################################################################################
27class CandidatEvaluationForm(ModelForm):
28 def __init__(self, *args, **kwargs):
29 self.candidat = kwargs.pop('candidat')
e34a2ae0 30 self.evaluateur = kwargs.pop('evaluateur')
83252c4c 31 super(CandidatEvaluationForm, self).__init__(*args, **kwargs)
32
33 def save(self):
34 super(CandidatEvaluationForm, self).save()
35
36 class Meta:
e34a2ae0 37 fields = ('note', 'commentaire')
2b3edf33 38 model = recr.CandidatEvaluation
83252c4c 39
40class EvaluateurForm(forms.Form):
8ea41642 41 evaluateurs = forms.ModelMultipleChoiceField(queryset=
27c81d11 42 recr.Evaluateur.objects.all())
83252c4c 43
44 def __init__(self, *args, **kwargs):
540dfae4 45 self.offres_emploi = kwargs.pop('offres_emploi')
83252c4c 46 super(EvaluateurForm, self).__init__(*args, **kwargs)
47
48 def save(self):
540dfae4
NBV
49 candidats = recr.Candidat.objects.\
50 filter(offre_emploi__in=self.offres_emploi)
540dfae4 51 for candidat in candidats:
21b02da5 52 for evaluateur in self.cleaned_data.get('evaluateurs', []):
c4874d66 53 candidat_evaluation = recr.CandidatEvaluation()
21b02da5
NBV
54 candidat_evaluation.candidat = candidat
55 candidat_evaluation.evaluateur = evaluateur
c4874d66 56 candidat_evaluation.save()
540dfae4 57
83252c4c 58
59################################################################################
60# OFFRE EMPLOI
61################################################################################
240940e1
NBV
62class CandidatPieceForm(emploi.CandidatPieceForm):
63 pass
86caaf03 64
240940e1
NBV
65class PostulerOffreEmploiForm(emploi.PostulerOffreEmploiForm):
66 pass
ec517164 67
a084e988 68class OffreEmploiForm(ModelForm):
e2968e84
NBV
69 poste = ModelChoiceField(queryset=rh.Poste.objects.all())
70
a084e988
NBV
71 class Meta:
72 model = recr.OffreEmploi
73
d333c690
NBV
74 def __init__(self, *args, **kwargs):
75 super(OffreEmploiForm, self).__init__(*args, **kwargs)
76
e2968e84
NBV
77 def save(self, *args, **kwargs):
78 kwargs2 = kwargs.copy()
79 kwargs2['commit'] = False
80 offre = super(OffreEmploiForm, self).save(*args, **kwargs2)
43198a9f 81 offre.poste = self.cleaned_data.get("poste").id
e2968e84
NBV
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
540dfae4
NBV
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:
1dd2d51f 94 raise forms.ValidationError("La date limite ne peut pas être \
a084e988 95 supérieure à la date d'affection.")
540dfae4 96 return cleaned_data
a084e988 97
d84c3a68 98################################################################################
99# TEMPLATE COURRIEL
100################################################################################
32834000
NBV
101class CandidatCourrielTemplateForm(ModelForm):
102 def get_template(self):
103 return self.data['template']
d84c3a68 104
32834000
NBV
105 class Meta:
106 model = recr.CandidatCourriel
107 fields = ('template', )
108
109class CandidatCourrielForm(ModelForm):
d84c3a68 110 def __init__(self, *args, **kwargs):
111 self.candidats = kwargs.pop('candidats')
32834000 112 self.template = kwargs.pop('template')
d84c3a68 113 super(CandidatCourrielForm, self).__init__(*args, **kwargs)
114
115 def save(self):
116 super(CandidatCourrielForm, self).save()
117
118 class Meta:
119 model = recr.CandidatCourriel
32834000 120 fields = ('sujet', 'plain_text', 'html')
d84c3a68 121