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