from django.forms.widgets import CheckboxSelectMultiple
from django.contrib.admin import widgets as admin_widgets
from form_utils.forms import BetterModelForm
-from django.forms import ModelForm
+from django.forms import ModelForm, ModelChoiceField, HiddenInput, CharField
from django.forms.models import BaseInlineFormSet
+from django.core.mail import send_mail
+from datamaster_modeles.models import Employe, Implantation, Region
from tinymce.widgets import TinyMCE
from captcha.fields import CaptchaField
from recrutement import models as recr
-from django.core.mail import send_mail
+from auf.django.emploi import forms as emploi
+from project.rh import models as rh
+from project.dae.utils import get_employe_from_user as get_emp
################################################################################
# EVALUATION
recr.Evaluateur.objects.all())
def __init__(self, *args, **kwargs):
- self.candidats = kwargs.pop('candidats')
+ self.offres_emploi = kwargs.pop('offres_emploi')
super(EvaluateurForm, self).__init__(*args, **kwargs)
def save(self):
- for candidat in self.candidats:
+ candidats = recr.Candidat.objects.\
+ filter(offre_emploi__in=self.offres_emploi)
+ for candidat in candidats:
for evaluateur in self.cleaned_data.get('evaluateurs', []):
candidat_evaluation = recr.CandidatEvaluation()
candidat_evaluation.candidat = candidat
candidat_evaluation.evaluateur = evaluateur
candidat_evaluation.save()
+
################################################################################
# OFFRE EMPLOI
################################################################################
-class CandidatPieceForm(inlineformset_factory(recr.Candidat,
- recr.CandidatPiece)):
- nom = forms.MultipleChoiceField(choices=recr.TYPE_PIECE_CHOICES,
- widget=CheckboxSelectMultiple)
+class CandidatPieceForm(emploi.CandidatPieceForm):
+ pass
-class PostulerOffreEmploiForm(ModelForm):
- captcha = CaptchaField()
+class PostulerOffreEmploiForm(emploi.PostulerOffreEmploiForm):
+ pass
- def __init__(self, *args, **kwargs):
- self.offre_emploi = kwargs.pop('offre_emploi')
- super(PostulerOffreEmploiForm, self).__init__(*args, **kwargs)
+class OffreEmploiForm(ModelForm):
+ poste = ModelChoiceField(queryset=rh.Poste.objects.all())
- def save(self, *args, **kwargs):
+ class Meta:
+ model = recr.OffreEmploi
+
+ def __init__(self, *args, **kwargs):
+ super(OffreEmploiForm, self).__init__(*args, **kwargs)
+
+ def save(self, *args, **kwargs):
kwargs2 = kwargs.copy()
kwargs2['commit'] = False
- postulation = super(PostulerOffreEmploiForm, self).save(*args, **kwargs2)
+ offre = super(OffreEmploiForm, self).save(*args, **kwargs2)
+ offre.poste = self.cleaned_data.get("poste").id
+ offre.poste_nom = self.cleaned_data.get("poste").nom
if 'commit' not in kwargs or kwargs['commit']:
- postulation.save()
- return postulation
-
- class Meta:
- model = recr.Candidat
- exclude = ('actif', 'offre_emploi',)
- fields = ('nom', 'prenom', 'genre', 'nationalite', 'situation_famille',
- 'nombre_dependant', 'niveau_diplome', 'employeur_actuel',
- 'poste_actuel', 'domaine_professionnel', 'telephone',
- 'email', 'adresse', 'ville', 'code_postal', 'etat_province',
- 'pays', 'captcha', )
+ offre.save()
+ return offre
+
+ def clean(self):
+ cleaned_data = self.cleaned_data
+ date_limite = cleaned_data.get("date_limite")
+ debut_affectation = cleaned_data.get("debut_affectation")
+
+ if date_limite and debut_affectation:
+ if date_limite > debut_affectation:
+ raise forms.ValidationError("La date limite ne peut pas être \
+ supérieure à la date d'affection.")
+ return cleaned_data
################################################################################
# TEMPLATE COURRIEL