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 | |
32834000 | 18 | from django.core.mail import send_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): | |
21b02da5 NBV |
45 | for candidat in self.candidats: |
46 | for evaluateur in self.cleaned_data.get('evaluateurs', []): | |
c4874d66 | 47 | candidat_evaluation = recr.CandidatEvaluation() |
21b02da5 NBV |
48 | candidat_evaluation.candidat = candidat |
49 | candidat_evaluation.evaluateur = evaluateur | |
c4874d66 | 50 | candidat_evaluation.save() |
83252c4c | 51 | |
52 | ################################################################################ | |
53 | # OFFRE EMPLOI | |
54 | ################################################################################ | |
f6749f29 | 55 | class CandidatPieceForm(inlineformset_factory(recr.Candidat, |
56 | recr.CandidatPiece)): | |
ee42ad96 | 57 | nom = forms.MultipleChoiceField(choices=recr.TYPE_PIECE_CHOICES, |
58 | widget=CheckboxSelectMultiple) | |
2b3edf33 | 59 | |
60 | class PostulerOffreEmploiForm(ModelForm): | |
86caaf03 | 61 | captcha = CaptchaField() |
62 | ||
2b3edf33 | 63 | def __init__(self, *args, **kwargs): |
ee42ad96 | 64 | self.offre_emploi = kwargs.pop('offre_emploi') |
8ea41642 | 65 | super(PostulerOffreEmploiForm, self).__init__(*args, **kwargs) |
66 | ||
f6749f29 | 67 | def save(self, *args, **kwargs): |
68 | kwargs2 = kwargs.copy() | |
69 | kwargs2['commit'] = False | |
70 | postulation = super(PostulerOffreEmploiForm, self).save(*args, **kwargs2) | |
71 | if 'commit' not in kwargs or kwargs['commit']: | |
72 | postulation.save() | |
73 | return postulation | |
8ea41642 | 74 | |
83252c4c | 75 | class Meta: |
2b3edf33 | 76 | model = recr.Candidat |
77 | exclude = ('actif', 'offre_emploi',) | |
4fd0c4a2 NBV |
78 | fields = ('nom', 'prenom', 'genre', 'nationalite', 'situation_famille', |
79 | 'nombre_dependant', 'niveau_diplome', 'employeur_actuel', | |
80 | 'poste_actuel', 'domaine_professionnel', 'telephone', | |
81 | 'email', 'adresse', 'ville', 'code_postal', 'etat_province', | |
82 | 'pays', 'captcha', ) | |
ec517164 | 83 | |
d84c3a68 | 84 | ################################################################################ |
85 | # TEMPLATE COURRIEL | |
86 | ################################################################################ | |
32834000 NBV |
87 | class CandidatCourrielTemplateForm(ModelForm): |
88 | def get_template(self): | |
89 | return self.data['template'] | |
d84c3a68 | 90 | |
32834000 NBV |
91 | class Meta: |
92 | model = recr.CandidatCourriel | |
93 | fields = ('template', ) | |
94 | ||
95 | class CandidatCourrielForm(ModelForm): | |
d84c3a68 | 96 | def __init__(self, *args, **kwargs): |
97 | self.candidats = kwargs.pop('candidats') | |
32834000 | 98 | self.template = kwargs.pop('template') |
d84c3a68 | 99 | super(CandidatCourrielForm, self).__init__(*args, **kwargs) |
100 | ||
101 | def save(self): | |
102 | super(CandidatCourrielForm, self).save() | |
103 | ||
104 | class Meta: | |
105 | model = recr.CandidatCourriel | |
32834000 | 106 | fields = ('sujet', 'plain_text', 'html') |
d84c3a68 | 107 |