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