Commit des modifications pour pouvoir merger
[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
83252c4c 11from django.forms import ModelForm
2b3edf33 12from django.forms.models import BaseInlineFormSet
ee42ad96 13
ec517164 14from tinymce.widgets import TinyMCE
86caaf03 15from captcha.fields import CaptchaField
ec517164 16
17from recrutement import models as recr
4e8340cf 18from recrutement.lib import send_templated_mail
83252c4c 19
20################################################################################
21# EVALUATION
22################################################################################
23class CandidatEvaluationForm(ModelForm):
24 def __init__(self, *args, **kwargs):
25 self.candidat = kwargs.pop('candidat')
e34a2ae0 26 self.evaluateur = kwargs.pop('evaluateur')
83252c4c 27 super(CandidatEvaluationForm, self).__init__(*args, **kwargs)
28
29 def save(self):
30 super(CandidatEvaluationForm, self).save()
31
32 class Meta:
e34a2ae0 33 fields = ('note', 'commentaire')
2b3edf33 34 model = recr.CandidatEvaluation
83252c4c 35
36class EvaluateurForm(forms.Form):
8ea41642 37 evaluateurs = forms.ModelMultipleChoiceField(queryset=
f6749f29 38 recr.UserProfile.objects.all())
83252c4c 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 d in self.candidats:
46 d.evaluateurs = self.cleaned_data.get('evaluateurs', [])
47 d.save()
48
49################################################################################
50# OFFRE EMPLOI
51################################################################################
f6749f29 52class CandidatPieceForm(inlineformset_factory(recr.Candidat,
53 recr.CandidatPiece)):
ee42ad96 54 nom = forms.MultipleChoiceField(choices=recr.TYPE_PIECE_CHOICES,
55 widget=CheckboxSelectMultiple)
2b3edf33 56
57class PostulerOffreEmploiForm(ModelForm):
86caaf03 58 captcha = CaptchaField()
59
2b3edf33 60 def __init__(self, *args, **kwargs):
ee42ad96 61 self.offre_emploi = kwargs.pop('offre_emploi')
8ea41642 62 super(PostulerOffreEmploiForm, self).__init__(*args, **kwargs)
63
f6749f29 64 def save(self, *args, **kwargs):
65 kwargs2 = kwargs.copy()
66 kwargs2['commit'] = False
67 postulation = super(PostulerOffreEmploiForm, self).save(*args, **kwargs2)
68 if 'commit' not in kwargs or kwargs['commit']:
69 postulation.save()
70 return postulation
8ea41642 71
83252c4c 72 class Meta:
2b3edf33 73 model = recr.Candidat
74 exclude = ('actif', 'offre_emploi',)
ee42ad96 75 widgets = dict(date_naissance=admin_widgets.AdminDateWidget(),)
2b3edf33 76 fields = ('nom', 'prenom', 'genre', 'nationalite', 'date_naissance',
77 'situation_famille', 'nombre_dependant', 'niveau_diplome',
78 'employeur_actuel', 'poste_actuel', 'domaine_professionnel',
ec517164 79 'telephone', 'email', 'adresse', 'ville', 'code_postal',
86caaf03 80 'etat_province', 'pays', 'captcha', )
ec517164 81
d84c3a68 82################################################################################
83# TEMPLATE COURRIEL
84################################################################################
85class CandidatCourrielForm(ModelForm):
86 #texte = forms.CharField(widget=TinyMCE())
87
88 def __init__(self, *args, **kwargs):
89 self.candidats = kwargs.pop('candidats')
90 super(CandidatCourrielForm, self).__init__(*args, **kwargs)
91
92 def save(self):
93 super(CandidatCourrielForm, self).save()
4e8340cf 94 #for cand in self.candidats:
95 #send_templated_mail()
d84c3a68 96
97 class Meta:
98 model = recr.CandidatCourriel
99 fields = ('template','titre', 'texte')
100