ee0c90c469165b977b28fc31f6028294927c8749
[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
12 from django.forms.models import BaseInlineFormSet
13
14 from tinymce.widgets import TinyMCE
15 from captcha.fields import CaptchaField
16
17 from recrutement import models as recr
18 from django.core.mail import send_mail
19 #from recrutement.lib import send_templated_mail
20
21 ################################################################################
22 # EVALUATION
23 ################################################################################
24 class CandidatEvaluationForm(ModelForm):
25 def __init__(self, *args, **kwargs):
26 self.candidat = kwargs.pop('candidat')
27 self.evaluateur = kwargs.pop('evaluateur')
28 super(CandidatEvaluationForm, self).__init__(*args, **kwargs)
29
30 def save(self):
31 super(CandidatEvaluationForm, self).save()
32
33 class Meta:
34 fields = ('note', 'commentaire')
35 model = recr.CandidatEvaluation
36
37 class EvaluateurForm(forms.Form):
38 evaluateurs = forms.ModelMultipleChoiceField(queryset=
39 recr.Evaluateur.objects.all())
40
41 def __init__(self, *args, **kwargs):
42 self.candidats = kwargs.pop('candidats')
43 super(EvaluateurForm, self).__init__(*args, **kwargs)
44
45 def save(self):
46 for candidat in self.candidats:
47 for evaluateur in self.cleaned_data.get('evaluateurs', []):
48 candidat_evaluation = recr.CandidatEvaluation()
49 candidat_evaluation.candidat = candidat
50 candidat_evaluation.evaluateur = evaluateur
51 candidat_evaluation.save()
52
53 ################################################################################
54 # OFFRE EMPLOI
55 ################################################################################
56 class CandidatPieceForm(inlineformset_factory(recr.Candidat,
57 recr.CandidatPiece)):
58 nom = forms.MultipleChoiceField(choices=recr.TYPE_PIECE_CHOICES,
59 widget=CheckboxSelectMultiple)
60
61 class PostulerOffreEmploiForm(ModelForm):
62 captcha = CaptchaField()
63
64 def __init__(self, *args, **kwargs):
65 self.offre_emploi = kwargs.pop('offre_emploi')
66 super(PostulerOffreEmploiForm, self).__init__(*args, **kwargs)
67
68 def save(self, *args, **kwargs):
69 kwargs2 = kwargs.copy()
70 kwargs2['commit'] = False
71 postulation = super(PostulerOffreEmploiForm, self).save(*args, **kwargs2)
72 if 'commit' not in kwargs or kwargs['commit']:
73 postulation.save()
74 return postulation
75
76 class Meta:
77 model = recr.Candidat
78 exclude = ('actif', 'offre_emploi',)
79 widgets = dict(date_naissance=admin_widgets.AdminDateWidget(),)
80 fields = ('nom', 'prenom', 'genre', 'nationalite', 'date_naissance',
81 'situation_famille', 'nombre_dependant', 'niveau_diplome',
82 'employeur_actuel', 'poste_actuel', 'domaine_professionnel',
83 'telephone', 'email', 'adresse', 'ville', 'code_postal',
84 'etat_province', 'pays', 'captcha', )
85
86 ################################################################################
87 # TEMPLATE COURRIEL
88 ################################################################################
89 class CandidatCourrielTemplateForm(ModelForm):
90 def get_template(self):
91 return self.data['template']
92
93 class Meta:
94 model = recr.CandidatCourriel
95 fields = ('template', )
96
97 class CandidatCourrielForm(ModelForm):
98 def __init__(self, *args, **kwargs):
99 self.candidats = kwargs.pop('candidats')
100 self.template = kwargs.pop('template')
101 super(CandidatCourrielForm, self).__init__(*args, **kwargs)
102
103 def save(self):
104 super(CandidatCourrielForm, self).save()
105
106 class Meta:
107 model = recr.CandidatCourriel
108 fields = ('sujet', 'plain_text', 'html')
109