| 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 | from django.core.mail import send_mail |
| 14 | |
| 15 | from tinymce.widgets import TinyMCE |
| 16 | from captcha.fields import CaptchaField |
| 17 | |
| 18 | from recrutement import models as recr |
| 19 | from auf.django.emploi import forms as emploi |
| 20 | |
| 21 | ################################################################################ |
| 22 | # EVALUATION |
| 23 | ################################################################################ |
| 24 | class CandidatEvaluationForm(ModelForm): |
| 25 | def __init__(self, *args, **kwargs): |
| 26 | self.candidat = kwargs.pop('candidat') |
| 27 | self.evaluateur = kwargs.pop('evaluateur') |
| 28 | super(CandidatEvaluationForm, self).__init__(*args, **kwargs) |
| 29 | |
| 30 | def save(self): |
| 31 | super(CandidatEvaluationForm, self).save() |
| 32 | |
| 33 | class Meta: |
| 34 | fields = ('note', 'commentaire') |
| 35 | model = recr.CandidatEvaluation |
| 36 | |
| 37 | class EvaluateurForm(forms.Form): |
| 38 | evaluateurs = forms.ModelMultipleChoiceField(queryset= |
| 39 | recr.Evaluateur.objects.all()) |
| 40 | |
| 41 | def __init__(self, *args, **kwargs): |
| 42 | self.offres_emploi = kwargs.pop('offres_emploi') |
| 43 | super(EvaluateurForm, self).__init__(*args, **kwargs) |
| 44 | |
| 45 | def save(self): |
| 46 | candidats = recr.Candidat.objects.\ |
| 47 | filter(offre_emploi__in=self.offres_emploi) |
| 48 | for candidat in candidats: |
| 49 | for evaluateur in self.cleaned_data.get('evaluateurs', []): |
| 50 | candidat_evaluation = recr.CandidatEvaluation() |
| 51 | candidat_evaluation.candidat = candidat |
| 52 | candidat_evaluation.evaluateur = evaluateur |
| 53 | candidat_evaluation.save() |
| 54 | |
| 55 | |
| 56 | ################################################################################ |
| 57 | # OFFRE EMPLOI |
| 58 | ################################################################################ |
| 59 | class CandidatPieceForm(emploi.CandidatPieceForm): |
| 60 | pass |
| 61 | |
| 62 | class PostulerOffreEmploiForm(emploi.PostulerOffreEmploiForm): |
| 63 | pass |
| 64 | |
| 65 | class OffreEmploiForm(ModelForm): |
| 66 | class Meta: |
| 67 | model = recr.OffreEmploi |
| 68 | |
| 69 | def clean(self): |
| 70 | cleaned_data = self.cleaned_data |
| 71 | date_limite = cleaned_data.get("date_limite") |
| 72 | debut_affectation = cleaned_data.get("debut_affectation") |
| 73 | |
| 74 | if date_limite and debut_affectation: |
| 75 | if date_limite > debut_affectation: |
| 76 | raise forms.ValidationError("La date limite ne peut être \ |
| 77 | supérieure à la date d'affection.") |
| 78 | |
| 79 | return cleaned_data |
| 80 | |
| 81 | ################################################################################ |
| 82 | # TEMPLATE COURRIEL |
| 83 | ################################################################################ |
| 84 | class CandidatCourrielTemplateForm(ModelForm): |
| 85 | def get_template(self): |
| 86 | return self.data['template'] |
| 87 | |
| 88 | class Meta: |
| 89 | model = recr.CandidatCourriel |
| 90 | fields = ('template', ) |
| 91 | |
| 92 | class CandidatCourrielForm(ModelForm): |
| 93 | def __init__(self, *args, **kwargs): |
| 94 | self.candidats = kwargs.pop('candidats') |
| 95 | self.template = kwargs.pop('template') |
| 96 | super(CandidatCourrielForm, self).__init__(*args, **kwargs) |
| 97 | |
| 98 | def save(self): |
| 99 | super(CandidatCourrielForm, self).save() |
| 100 | |
| 101 | class Meta: |
| 102 | model = recr.CandidatCourriel |
| 103 | fields = ('sujet', 'plain_text', 'html') |
| 104 | |