1640: Aide pour le nombre de dépendants
[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
83252c4c 18
19################################################################################
20# EVALUATION
21################################################################################
22class CandidatEvaluationForm(ModelForm):
23 def __init__(self, *args, **kwargs):
24 self.candidat = kwargs.pop('candidat')
e34a2ae0 25 self.evaluateur = kwargs.pop('evaluateur')
83252c4c 26 super(CandidatEvaluationForm, self).__init__(*args, **kwargs)
27
28 def save(self):
29 super(CandidatEvaluationForm, self).save()
30
31 class Meta:
e34a2ae0 32 fields = ('note', 'commentaire')
2b3edf33 33 model = recr.CandidatEvaluation
83252c4c 34
35class EvaluateurForm(forms.Form):
8ea41642 36 evaluateurs = forms.ModelMultipleChoiceField(queryset=
f6749f29 37 recr.UserProfile.objects.all())
83252c4c 38
39 def __init__(self, *args, **kwargs):
40 self.candidats = kwargs.pop('candidats')
41 super(EvaluateurForm, self).__init__(*args, **kwargs)
42
43 def save(self):
44 for d in self.candidats:
45 d.evaluateurs = self.cleaned_data.get('evaluateurs', [])
46 d.save()
47
48################################################################################
49# OFFRE EMPLOI
50################################################################################
f6749f29 51class CandidatPieceForm(inlineformset_factory(recr.Candidat,
52 recr.CandidatPiece)):
ee42ad96 53 nom = forms.MultipleChoiceField(choices=recr.TYPE_PIECE_CHOICES,
54 widget=CheckboxSelectMultiple)
2b3edf33 55
56class PostulerOffreEmploiForm(ModelForm):
86caaf03 57 captcha = CaptchaField()
58
2b3edf33 59 def __init__(self, *args, **kwargs):
ee42ad96 60 self.offre_emploi = kwargs.pop('offre_emploi')
8ea41642 61 super(PostulerOffreEmploiForm, self).__init__(*args, **kwargs)
62
f6749f29 63 def save(self, *args, **kwargs):
64 kwargs2 = kwargs.copy()
65 kwargs2['commit'] = False
66 postulation = super(PostulerOffreEmploiForm, self).save(*args, **kwargs2)
67 if 'commit' not in kwargs or kwargs['commit']:
68 postulation.save()
69 return postulation
8ea41642 70
83252c4c 71 class Meta:
2b3edf33 72 model = recr.Candidat
73 exclude = ('actif', 'offre_emploi',)
ee42ad96 74 widgets = dict(date_naissance=admin_widgets.AdminDateWidget(),)
2b3edf33 75 fields = ('nom', 'prenom', 'genre', 'nationalite', 'date_naissance',
76 'situation_famille', 'nombre_dependant', 'niveau_diplome',
77 'employeur_actuel', 'poste_actuel', 'domaine_professionnel',
ec517164 78 'telephone', 'email', 'adresse', 'ville', 'code_postal',
86caaf03 79 'etat_province', 'pays', 'captcha', )
ec517164 80