1677: Changer les informations concernant le SMTP + composer message. 1655: Envois...
[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
32834000 18from django.core.mail import send_mail
f1491a6f 19#from recrutement.lib import send_templated_mail
83252c4c 20
21################################################################################
22# EVALUATION
23################################################################################
24class 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
37class EvaluateurForm(forms.Form):
8ea41642 38 evaluateurs = forms.ModelMultipleChoiceField(queryset=
27c81d11 39 recr.Evaluateur.objects.all())
83252c4c 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):
21b02da5
NBV
46 for candidat in self.candidats:
47 for evaluateur in self.cleaned_data.get('evaluateurs', []):
c4874d66 48 candidat_evaluation = recr.CandidatEvaluation()
21b02da5
NBV
49 candidat_evaluation.candidat = candidat
50 candidat_evaluation.evaluateur = evaluateur
c4874d66 51 candidat_evaluation.save()
83252c4c 52
53################################################################################
54# OFFRE EMPLOI
55################################################################################
f6749f29 56class CandidatPieceForm(inlineformset_factory(recr.Candidat,
57 recr.CandidatPiece)):
ee42ad96 58 nom = forms.MultipleChoiceField(choices=recr.TYPE_PIECE_CHOICES,
59 widget=CheckboxSelectMultiple)
2b3edf33 60
61class PostulerOffreEmploiForm(ModelForm):
86caaf03 62 captcha = CaptchaField()
63
2b3edf33 64 def __init__(self, *args, **kwargs):
ee42ad96 65 self.offre_emploi = kwargs.pop('offre_emploi')
8ea41642 66 super(PostulerOffreEmploiForm, self).__init__(*args, **kwargs)
67
f6749f29 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
8ea41642 75
83252c4c 76 class Meta:
2b3edf33 77 model = recr.Candidat
78 exclude = ('actif', 'offre_emploi',)
ee42ad96 79 widgets = dict(date_naissance=admin_widgets.AdminDateWidget(),)
2b3edf33 80 fields = ('nom', 'prenom', 'genre', 'nationalite', 'date_naissance',
81 'situation_famille', 'nombre_dependant', 'niveau_diplome',
82 'employeur_actuel', 'poste_actuel', 'domaine_professionnel',
ec517164 83 'telephone', 'email', 'adresse', 'ville', 'code_postal',
86caaf03 84 'etat_province', 'pays', 'captcha', )
ec517164 85
d84c3a68 86################################################################################
87# TEMPLATE COURRIEL
88################################################################################
32834000
NBV
89class CandidatCourrielTemplateForm(ModelForm):
90 def get_template(self):
91 return self.data['template']
d84c3a68 92
32834000
NBV
93 class Meta:
94 model = recr.CandidatCourriel
95 fields = ('template', )
96
97class CandidatCourrielForm(ModelForm):
d84c3a68 98 def __init__(self, *args, **kwargs):
99 self.candidats = kwargs.pop('candidats')
32834000 100 self.template = kwargs.pop('template')
d84c3a68 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
32834000 108 fields = ('sujet', 'plain_text', 'html')
d84c3a68 109