7a4a9e332d60749e13b761158709e0b567bfb1e1
[auf_django_emploi.git] / auf / django / emploi / forms.py
1 # -*- encoding: utf-8 -*-
2
3 from django import forms
4 from django.forms.models import inlineformset_factory
5 from django.forms.widgets import CheckboxSelectMultiple
6 from django.forms import ModelForm
7
8 from captcha.fields import CaptchaField
9
10 from models import *
11
12 ################################################################################
13 # OFFRE EMPLOI
14 ################################################################################
15 class CandidatPieceForm(inlineformset_factory(Candidat,
16 CandidatPiece)):
17 nom = forms.MultipleChoiceField(choices=TYPE_PIECE_CHOICES,
18 widget=CheckboxSelectMultiple)
19
20 def __init__(self, *args, **kwargs):
21 super(CandidatPieceForm, self).__init__(*args, **kwargs)
22
23 def save(self, *args, **kwargs):
24 super(CandidatPieceForm, self).save(*args, **kwargs)
25
26
27 class PostulerOffreEmploiForm(ModelForm):
28 captcha = CaptchaField()
29 action = "http://127.0.0.1:8000/api/candidat_add/"
30
31 def __init__(self, *args, **kwargs):
32 self.offre_emploi = kwargs.pop('offre_id')
33 super(PostulerOffreEmploiForm, self).__init__(*args, **kwargs)
34
35 def save(self, *args, **kwargs):
36 kwargs2 = kwargs.copy()
37 kwargs2['commit'] = False
38 postulation = super(PostulerOffreEmploiForm, self).save(*args, **kwargs2)
39 if 'commit' not in kwargs or kwargs['commit']:
40 postulation.save()
41 return postulation
42
43 class Meta:
44 model = Candidat
45 exclude = ('actif', 'offre_emploi',)
46 fields = ('nom', 'prenom', 'genre', 'nationalite', 'situation_famille',
47 'nombre_dependant', 'niveau_diplome', 'employeur_actuel',
48 'poste_actuel', 'domaine_professionnel', 'telephone',
49 'email', 'adresse', 'ville', 'code_postal', 'etat_province',
50 'pays', 'captcha', )