f3a8b9bc467c2e7c8617475d0533094073fe1fb0
[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 form_utils.forms import BetterModelForm
8 from django.forms import ModelForm
9 from django.forms.models import BaseInlineFormSet
10 from tinymce.widgets import TinyMCE
11 from captcha.fields import CaptchaField
12
13 from recrutement import models as recr
14
15 ################################################################################
16 # EVALUATION
17 ################################################################################
18 class CandidatEvaluationForm(ModelForm):
19 def __init__(self, *args, **kwargs):
20 self.candidat = kwargs.pop('candidat')
21 self.evaluateur = kwargs.pop('evaluateur')
22 super(CandidatEvaluationForm, self).__init__(*args, **kwargs)
23
24 def save(self):
25 super(CandidatEvaluationForm, self).save()
26
27 class Meta:
28 fields = ('note', 'commentaire')
29 model = recr.CandidatEvaluation
30
31 class EvaluateurForm(forms.Form):
32 evaluateurs = forms.ModelMultipleChoiceField(queryset=
33 recr.UserProfile.objects.all())
34
35 def __init__(self, *args, **kwargs):
36 self.candidats = kwargs.pop('candidats')
37 super(EvaluateurForm, self).__init__(*args, **kwargs)
38
39 def save(self):
40 for d in self.candidats:
41 d.evaluateurs = self.cleaned_data.get('evaluateurs', [])
42 d.save()
43
44 ################################################################################
45 # OFFRE EMPLOI
46 ################################################################################
47 class CandidatPieceForm(inlineformset_factory(recr.Candidat,
48 recr.CandidatPiece)):
49 pass
50
51 class PostulerOffreEmploiForm(ModelForm):
52 captcha = CaptchaField()
53
54 def __init__(self, *args, **kwargs):
55 self.offre_emploi = kwargs.pop('offre_emploi')
56 super(PostulerOffreEmploiForm, self).__init__(*args, **kwargs)
57
58 def save(self, *args, **kwargs):
59 kwargs2 = kwargs.copy()
60 kwargs2['commit'] = False
61 postulation = super(PostulerOffreEmploiForm, self).save(*args, **kwargs2)
62 if 'commit' not in kwargs or kwargs['commit']:
63 postulation.save()
64 return postulation
65
66 class Meta:
67 model = recr.Candidat
68 exclude = ('actif', 'offre_emploi',)
69 fields = ('nom', 'prenom', 'genre', 'nationalite', 'date_naissance',
70 'situation_famille', 'nombre_dependant', 'niveau_diplome',
71 'employeur_actuel', 'poste_actuel', 'domaine_professionnel',
72 'telephone', 'email', 'adresse', 'ville', 'code_postal',
73 'etat_province', 'pays', 'captcha', )
74