Commit | Line | Data |
---|---|---|
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 | |
ee42ad96 | 7 | from datetime import timedelta |
8 | from django.forms.widgets import CheckboxSelectMultiple | |
9 | from django.contrib.admin import widgets as admin_widgets | |
8ea41642 | 10 | from form_utils.forms import BetterModelForm |
83252c4c | 11 | from django.forms import ModelForm |
2b3edf33 | 12 | from django.forms.models import BaseInlineFormSet |
ee42ad96 | 13 | |
ec517164 | 14 | from tinymce.widgets import TinyMCE |
86caaf03 | 15 | from captcha.fields import CaptchaField |
ec517164 | 16 | |
17 | from recrutement import models as recr | |
f1491a6f | 18 | #from recrutement.lib import send_templated_mail |
83252c4c | 19 | |
20 | ################################################################################ | |
21 | # EVALUATION | |
22 | ################################################################################ | |
23 | class CandidatEvaluationForm(ModelForm): | |
24 | def __init__(self, *args, **kwargs): | |
25 | self.candidat = kwargs.pop('candidat') | |
e34a2ae0 | 26 | self.evaluateur = kwargs.pop('evaluateur') |
83252c4c | 27 | super(CandidatEvaluationForm, self).__init__(*args, **kwargs) |
28 | ||
29 | def save(self): | |
30 | super(CandidatEvaluationForm, self).save() | |
31 | ||
32 | class Meta: | |
e34a2ae0 | 33 | fields = ('note', 'commentaire') |
2b3edf33 | 34 | model = recr.CandidatEvaluation |
83252c4c | 35 | |
36 | class EvaluateurForm(forms.Form): | |
8ea41642 | 37 | evaluateurs = forms.ModelMultipleChoiceField(queryset= |
27c81d11 | 38 | recr.Evaluateur.objects.all()) |
83252c4c | 39 | |
40 | def __init__(self, *args, **kwargs): | |
41 | self.candidats = kwargs.pop('candidats') | |
42 | super(EvaluateurForm, self).__init__(*args, **kwargs) | |
43 | ||
44 | def save(self): | |
45 | for d in self.candidats: | |
c4874d66 NBV |
46 | for e in self.cleaned_data.get('evaluateurs', []): |
47 | candidat_evaluation = recr.CandidatEvaluation() | |
48 | candidat_evaluation.candidat = d | |
49 | candidat_evaluation.evaluateur = e | |
50 | import pdb;pdb.set_trace() | |
51 | candidat_evaluation.save() | |
83252c4c | 52 | |
53 | ################################################################################ | |
54 | # OFFRE EMPLOI | |
55 | ################################################################################ | |
f6749f29 | 56 | class CandidatPieceForm(inlineformset_factory(recr.Candidat, |
57 | recr.CandidatPiece)): | |
ee42ad96 | 58 | nom = forms.MultipleChoiceField(choices=recr.TYPE_PIECE_CHOICES, |
59 | widget=CheckboxSelectMultiple) | |
2b3edf33 | 60 | |
61 | class PostulerOffreEmploiForm(ModelForm): | |
86caaf03 | 62 | captcha = CaptchaField() |
63 | ||
2b3edf33 | 64 | def __init__(self, *args, **kwargs): |
ee42ad96 | 65 | self.offre_emploi = kwargs.pop('offre_emploi') |
8ea41642 | 66 | super(PostulerOffreEmploiForm, self).__init__(*args, **kwargs) |
67 | ||
f6749f29 | 68 | def save(self, *args, **kwargs): |
69 | kwargs2 = kwargs.copy() | |
70 | kwargs2['commit'] = False | |
71 | postulation = super(PostulerOffreEmploiForm, self).save(*args, **kwargs2) | |
72 | if 'commit' not in kwargs or kwargs['commit']: | |
73 | postulation.save() | |
74 | return postulation | |
8ea41642 | 75 | |
83252c4c | 76 | class Meta: |
2b3edf33 | 77 | model = recr.Candidat |
78 | exclude = ('actif', 'offre_emploi',) | |
ee42ad96 | 79 | widgets = dict(date_naissance=admin_widgets.AdminDateWidget(),) |
2b3edf33 | 80 | fields = ('nom', 'prenom', 'genre', 'nationalite', 'date_naissance', |
81 | 'situation_famille', 'nombre_dependant', 'niveau_diplome', | |
82 | 'employeur_actuel', 'poste_actuel', 'domaine_professionnel', | |
ec517164 | 83 | 'telephone', 'email', 'adresse', 'ville', 'code_postal', |
86caaf03 | 84 | 'etat_province', 'pays', 'captcha', ) |
ec517164 | 85 | |
d84c3a68 | 86 | ################################################################################ |
87 | # TEMPLATE COURRIEL | |
88 | ################################################################################ | |
89 | class CandidatCourrielForm(ModelForm): | |
90 | #texte = forms.CharField(widget=TinyMCE()) | |
91 | ||
92 | def __init__(self, *args, **kwargs): | |
93 | self.candidats = kwargs.pop('candidats') | |
94 | super(CandidatCourrielForm, self).__init__(*args, **kwargs) | |
95 | ||
96 | def save(self): | |
97 | super(CandidatCourrielForm, self).save() | |
4e8340cf | 98 | #for cand in self.candidats: |
99 | #send_templated_mail() | |
d84c3a68 | 100 | |
101 | class Meta: | |
102 | model = recr.CandidatCourriel | |
103 | fields = ('template','titre', 'texte') | |
104 |