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 recrutement.lib import send_templated_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 d in self.candidats:
- d.evaluateurs = self.cleaned_data.get('evaluateurs', [])
- d.save()
+ 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 PostulerOffreEmploiForm(ModelForm):
- captcha = CaptchaField()
-
- def __init__(self, *args, **kwargs):
- self.offre_emploi = kwargs.pop('offre_emploi')
- super(PostulerOffreEmploiForm, self).__init__(*args, **kwargs)
-
- def save(self, *args, **kwargs):
- kwargs2 = kwargs.copy()
- kwargs2['commit'] = False
- postulation = super(PostulerOffreEmploiForm, self).save(*args, **kwargs2)
- if 'commit' not in kwargs or kwargs['commit']:
- postulation.save()
- return postulation
-
- class Meta:
- model = recr.Candidat
- exclude = ('actif', 'offre_emploi',)
- widgets = dict(date_naissance=admin_widgets.AdminDateWidget(),)
- fields = ('nom', 'prenom', 'genre', 'nationalite', 'date_naissance',
- 'situation_famille', 'nombre_dependant', 'niveau_diplome',
- 'employeur_actuel', 'poste_actuel', 'domaine_professionnel',
- 'telephone', 'email', 'adresse', 'ville', 'code_postal',
- 'etat_province', 'pays', 'captcha', )
+class CandidatPieceForm(emploi.CandidatPieceForm):
+ pass
+
+class PostulerOffreEmploiForm(emploi.PostulerOffreEmploiForm):
+ pass
+
+class OffreEmploiForm(ModelForm):
+ #poste = ModelChoiceField(queryset=rh.Poste.objects.all())
+
+ #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
+ # 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']:
+ # 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
################################################################################
-class CandidatCourrielForm(ModelForm):
- #texte = forms.CharField(widget=TinyMCE())
+class CandidatCourrielTemplateForm(ModelForm):
+ def get_template(self):
+ return self.data['template']
+
+ class Meta:
+ model = recr.CandidatCourriel
+ fields = ('template', )
+class CandidatCourrielForm(ModelForm):
def __init__(self, *args, **kwargs):
self.candidats = kwargs.pop('candidats')
+ self.template = kwargs.pop('template')
super(CandidatCourrielForm, self).__init__(*args, **kwargs)
def save(self):
super(CandidatCourrielForm, self).save()
- #for cand in self.candidats:
- #send_templated_mail()
class Meta:
model = recr.CandidatCourriel
- fields = ('template','titre', 'texte')
+ fields = ('sujet', 'plain_text', 'html')