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