Retrait de la restriction des régions lors de l'ajout d'une offre d'emploi
[auf_rh_dae.git] / project / recrutement / forms.py
... / ...
CommitLineData
1# -*- encoding: utf-8 -*-
2
3import os
4from django import forms
5from django.contrib import admin
6from django.forms.models import inlineformset_factory
7from datetime import timedelta
8from django.forms.widgets import CheckboxSelectMultiple
9from django.contrib.admin import widgets as admin_widgets
10from form_utils.forms import BetterModelForm
11from django.forms import ModelForm
12from django.forms.models import BaseInlineFormSet
13
14from tinymce.widgets import TinyMCE
15from captcha.fields import CaptchaField
16
17from recrutement import models as recr
18
19################################################################################
20# EVALUATION
21################################################################################
22class CandidatEvaluationForm(ModelForm):
23 def __init__(self, *args, **kwargs):
24 self.candidat = kwargs.pop('candidat')
25 self.evaluateur = kwargs.pop('evaluateur')
26 super(CandidatEvaluationForm, self).__init__(*args, **kwargs)
27
28 def save(self):
29 super(CandidatEvaluationForm, self).save()
30
31 class Meta:
32 fields = ('note', 'commentaire')
33 model = recr.CandidatEvaluation
34
35class EvaluateurForm(forms.Form):
36 evaluateurs = forms.ModelMultipleChoiceField(queryset=
37 recr.UserProfile.objects.all())
38
39 def __init__(self, *args, **kwargs):
40 self.candidats = kwargs.pop('candidats')
41 super(EvaluateurForm, self).__init__(*args, **kwargs)
42
43 def save(self):
44 for d in self.candidats:
45 d.evaluateurs = self.cleaned_data.get('evaluateurs', [])
46 d.save()
47
48################################################################################
49# OFFRE EMPLOI
50################################################################################
51class CandidatPieceForm(inlineformset_factory(recr.Candidat,
52 recr.CandidatPiece)):
53 nom = forms.MultipleChoiceField(choices=recr.TYPE_PIECE_CHOICES,
54 widget=CheckboxSelectMultiple)
55
56class PostulerOffreEmploiForm(ModelForm):
57 captcha = CaptchaField()
58
59 def __init__(self, *args, **kwargs):
60 self.offre_emploi = kwargs.pop('offre_emploi')
61 super(PostulerOffreEmploiForm, self).__init__(*args, **kwargs)
62
63 def save(self, *args, **kwargs):
64 kwargs2 = kwargs.copy()
65 kwargs2['commit'] = False
66 postulation = super(PostulerOffreEmploiForm, self).save(*args, **kwargs2)
67 if 'commit' not in kwargs or kwargs['commit']:
68 postulation.save()
69 return postulation
70
71 class Meta:
72 model = recr.Candidat
73 exclude = ('actif', 'offre_emploi',)
74 widgets = dict(date_naissance=admin_widgets.AdminDateWidget(),)
75 fields = ('nom', 'prenom', 'genre', 'nationalite', 'date_naissance',
76 'situation_famille', 'nombre_dependant', 'niveau_diplome',
77 'employeur_actuel', 'poste_actuel', 'domaine_professionnel',
78 'telephone', 'email', 'adresse', 'ville', 'code_postal',
79 'etat_province', 'pays', 'captcha', )
80