Pièces jointes et 1852:Changer les adresse hardcodé dans l'API
[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 tinymce.widgets import TinyMCE
16 from captcha.fields import CaptchaField
17
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
22
23 ################################################################################
24 # EVALUATION
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)
31
32 def save(self):
33 super(CandidatEvaluationForm, self).save()
34
35 class Meta:
36 fields = ('note', 'commentaire')
37 model = recr.CandidatEvaluation
38
39 class EvaluateurForm(forms.Form):
40 evaluateurs = forms.ModelMultipleChoiceField(queryset=
41 recr.Evaluateur.objects.all())
42
43 def __init__(self, *args, **kwargs):
44 self.offres_emploi = kwargs.pop('offres_emploi')
45 super(EvaluateurForm, self).__init__(*args, **kwargs)
46
47 def save(self):
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()
56
57
58 ################################################################################
59 # OFFRE EMPLOI
60 ################################################################################
61 class CandidatPieceForm(emploi.CandidatPieceForm):
62 pass
63
64 class PostulerOffreEmploiForm(emploi.PostulerOffreEmploiForm):
65 pass
66
67 class OffreEmploiForm(ModelForm):
68 poste = ModelChoiceField(queryset=rh.Poste.objects.all())
69
70 class Meta:
71 model = recr.OffreEmploi
72
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']:
80 offre.save()
81 return offre
82
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:
90 raise forms.ValidationError("La date limite ne peut pas être \
91 supérieure à la date d'affection.")
92
93 return cleaned_data
94
95 ################################################################################
96 # TEMPLATE COURRIEL
97 ################################################################################
98 class CandidatCourrielTemplateForm(ModelForm):
99 def get_template(self):
100 return self.data['template']
101
102 class Meta:
103 model = recr.CandidatCourriel
104 fields = ('template', )
105
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)
111
112 def save(self):
113 super(CandidatCourrielForm, self).save()
114
115 class Meta:
116 model = recr.CandidatCourriel
117 fields = ('sujet', 'plain_text', 'html')
118