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