| 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 datetime import timedelta |
| 8 | from django.forms.widgets import CheckboxSelectMultiple |
| 9 | from django.contrib.admin import widgets as admin_widgets |
| 10 | from form_utils.forms import BetterModelForm |
| 11 | from django.forms import ModelForm |
| 12 | from django.forms.models import BaseInlineFormSet |
| 13 | |
| 14 | from tinymce.widgets import TinyMCE |
| 15 | from captcha.fields import CaptchaField |
| 16 | |
| 17 | from recrutement import models as recr |
| 18 | |
| 19 | ################################################################################ |
| 20 | # EVALUATION |
| 21 | ################################################################################ |
| 22 | class 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 | |
| 35 | class 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 | ################################################################################ |
| 51 | class CandidatPieceForm(inlineformset_factory(recr.Candidat, |
| 52 | recr.CandidatPiece)): |
| 53 | nom = forms.MultipleChoiceField(choices=recr.TYPE_PIECE_CHOICES, |
| 54 | widget=CheckboxSelectMultiple) |
| 55 | |
| 56 | class 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 | |