Commit | Line | Data |
---|---|---|
83252c4c | 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 | |
ee42ad96 | 7 | from datetime import timedelta |
8 | from django.forms.widgets import CheckboxSelectMultiple | |
9 | from django.contrib.admin import widgets as admin_widgets | |
8ea41642 | 10 | from form_utils.forms import BetterModelForm |
83252c4c | 11 | from django.forms import ModelForm |
2b3edf33 | 12 | from django.forms.models import BaseInlineFormSet |
240940e1 | 13 | from django.core.mail import send_mail |
ee42ad96 | 14 | |
ec517164 | 15 | from tinymce.widgets import TinyMCE |
86caaf03 | 16 | from captcha.fields import CaptchaField |
ec517164 | 17 | |
18 | from recrutement import models as recr | |
240940e1 NBV |
19 | from auf.django.emploi import forms as emploi |
20 | ||
83252c4c | 21 | ################################################################################ |
22 | # EVALUATION | |
23 | ################################################################################ | |
24 | class CandidatEvaluationForm(ModelForm): | |
25 | def __init__(self, *args, **kwargs): | |
26 | self.candidat = kwargs.pop('candidat') | |
e34a2ae0 | 27 | self.evaluateur = kwargs.pop('evaluateur') |
83252c4c | 28 | super(CandidatEvaluationForm, self).__init__(*args, **kwargs) |
29 | ||
30 | def save(self): | |
31 | super(CandidatEvaluationForm, self).save() | |
32 | ||
33 | class Meta: | |
e34a2ae0 | 34 | fields = ('note', 'commentaire') |
2b3edf33 | 35 | model = recr.CandidatEvaluation |
83252c4c | 36 | |
37 | class EvaluateurForm(forms.Form): | |
8ea41642 | 38 | evaluateurs = forms.ModelMultipleChoiceField(queryset= |
27c81d11 | 39 | recr.Evaluateur.objects.all()) |
83252c4c | 40 | |
41 | def __init__(self, *args, **kwargs): | |
540dfae4 | 42 | self.offres_emploi = kwargs.pop('offres_emploi') |
83252c4c | 43 | super(EvaluateurForm, self).__init__(*args, **kwargs) |
44 | ||
45 | def save(self): | |
540dfae4 NBV |
46 | candidats = recr.Candidat.objects.\ |
47 | filter(offre_emploi__in=self.offres_emploi) | |
540dfae4 | 48 | for candidat in candidats: |
21b02da5 | 49 | for evaluateur in self.cleaned_data.get('evaluateurs', []): |
c4874d66 | 50 | candidat_evaluation = recr.CandidatEvaluation() |
21b02da5 NBV |
51 | candidat_evaluation.candidat = candidat |
52 | candidat_evaluation.evaluateur = evaluateur | |
c4874d66 | 53 | candidat_evaluation.save() |
540dfae4 | 54 | |
83252c4c | 55 | |
56 | ################################################################################ | |
57 | # OFFRE EMPLOI | |
58 | ################################################################################ | |
240940e1 NBV |
59 | class CandidatPieceForm(emploi.CandidatPieceForm): |
60 | pass | |
86caaf03 | 61 | |
240940e1 NBV |
62 | class PostulerOffreEmploiForm(emploi.PostulerOffreEmploiForm): |
63 | pass | |
ec517164 | 64 | |
a084e988 NBV |
65 | class OffreEmploiForm(ModelForm): |
66 | class Meta: | |
67 | model = recr.OffreEmploi | |
68 | ||
540dfae4 NBV |
69 | def clean(self): |
70 | cleaned_data = self.cleaned_data | |
71 | date_limite = cleaned_data.get("date_limite") | |
72 | debut_affectation = cleaned_data.get("debut_affectation") | |
73 | ||
74 | if date_limite and debut_affectation: | |
75 | if date_limite > debut_affectation: | |
a084e988 NBV |
76 | raise forms.ValidationError("La date limite ne peut être \ |
77 | supérieure à la date d'affection.") | |
78 | ||
540dfae4 | 79 | return cleaned_data |
a084e988 | 80 | |
d84c3a68 | 81 | ################################################################################ |
82 | # TEMPLATE COURRIEL | |
83 | ################################################################################ | |
32834000 NBV |
84 | class CandidatCourrielTemplateForm(ModelForm): |
85 | def get_template(self): | |
86 | return self.data['template'] | |
d84c3a68 | 87 | |
32834000 NBV |
88 | class Meta: |
89 | model = recr.CandidatCourriel | |
90 | fields = ('template', ) | |
91 | ||
92 | class CandidatCourrielForm(ModelForm): | |
d84c3a68 | 93 | def __init__(self, *args, **kwargs): |
94 | self.candidats = kwargs.pop('candidats') | |
32834000 | 95 | self.template = kwargs.pop('template') |
d84c3a68 | 96 | super(CandidatCourrielForm, self).__init__(*args, **kwargs) |
97 | ||
98 | def save(self): | |
99 | super(CandidatCourrielForm, self).save() | |
100 | ||
101 | class Meta: | |
102 | model = recr.CandidatCourriel | |
32834000 | 103 | fields = ('sujet', 'plain_text', 'html') |
d84c3a68 | 104 |