83252c4c |
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 |
8ea41642 |
7 | from form_utils.forms import BetterModelForm |
83252c4c |
8 | from django.forms import ModelForm |
2b3edf33 |
9 | from recrutement import models as recr |
10 | from django.forms.models import BaseInlineFormSet |
83252c4c |
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') |
2b3edf33 |
25 | model = recr.CandidatEvaluation |
83252c4c |
26 | |
27 | class EvaluateurForm(forms.Form): |
8ea41642 |
28 | evaluateurs = forms.ModelMultipleChoiceField(queryset= |
f6749f29 |
29 | recr.UserProfile.objects.all()) |
83252c4c |
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 | ################################################################################ |
f6749f29 |
43 | class CandidatPieceForm(inlineformset_factory(recr.Candidat, |
44 | recr.CandidatPiece)): |
2b3edf33 |
45 | pass |
46 | |
47 | class PostulerOffreEmploiForm(ModelForm): |
48 | def __init__(self, *args, **kwargs): |
2adf9e0c |
49 | self.offre_emploi = kwargs.pop('offre_emploi') |
8ea41642 |
50 | super(PostulerOffreEmploiForm, self).__init__(*args, **kwargs) |
51 | |
f6749f29 |
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 |
8ea41642 |
59 | |
83252c4c |
60 | class Meta: |
2b3edf33 |
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', ) |