2018-02-02 09:55:09 +01:00
|
|
|
|
import os
|
|
|
|
|
|
|
2018-01-26 18:19:16 +01:00
|
|
|
|
from django.conf import settings
|
|
|
|
|
|
from django.contrib import messages
|
2018-02-02 09:55:09 +01:00
|
|
|
|
from django.http import HttpResponse
|
|
|
|
|
|
from django.shortcuts import redirect
|
2018-01-26 18:19:16 +01:00
|
|
|
|
from django.template import loader
|
2018-02-02 09:55:09 +01:00
|
|
|
|
from django.urls import reverse, reverse_lazy
|
2018-01-26 18:19:16 +01:00
|
|
|
|
from django.utils import timezone
|
|
|
|
|
|
|
2018-04-12 11:01:45 +02:00
|
|
|
|
from stages.base_views import EmailConfirmationBaseView
|
2018-02-02 09:55:09 +01:00
|
|
|
|
from candidats.models import Candidate, Interview
|
|
|
|
|
|
from .pdf import InscriptionSummaryPDF
|
2018-01-26 18:19:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
2018-04-12 11:01:45 +02:00
|
|
|
|
class CandidateConfirmationView(EmailConfirmationBaseView):
|
|
|
|
|
|
person_model = Candidate
|
2018-01-26 18:19:16 +01:00
|
|
|
|
success_url = reverse_lazy('admin:candidats_candidate_changelist')
|
2018-04-12 11:01:45 +02:00
|
|
|
|
error_message = "Échec d’envoi pour le candidat {person} ({err})"
|
2018-02-02 09:55:09 +01:00
|
|
|
|
candidate_date_field = None
|
|
|
|
|
|
|
2018-04-12 11:01:45 +02:00
|
|
|
|
def on_success(self, candidate):
|
|
|
|
|
|
setattr(candidate, self.candidate_date_field, timezone.now())
|
|
|
|
|
|
candidate.save()
|
2018-02-02 09:55:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
2018-04-12 11:01:45 +02:00
|
|
|
|
class ConfirmationView(CandidateConfirmationView):
|
2018-06-08 13:50:09 +02:00
|
|
|
|
"""
|
|
|
|
|
|
Email confirming the receipt of the registration form
|
|
|
|
|
|
"""
|
|
|
|
|
|
success_message = "Une confirmation d'inscription a été envoyée à {person}"
|
2018-02-02 09:55:09 +01:00
|
|
|
|
candidate_date_field = 'confirmation_date'
|
|
|
|
|
|
title = "Confirmation de réception de dossier"
|
|
|
|
|
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
|
|
candidate = Candidate.objects.get(pk=self.kwargs['pk'])
|
2018-06-08 13:50:09 +02:00
|
|
|
|
if candidate.section not in {'ASA', 'ASE', 'ASSC', 'EDE', 'EDS'}:
|
|
|
|
|
|
messages.error(request, "Ce formulaire n'est disponible que pour les candidats FE ou ES")
|
2018-02-15 12:13:04 +01:00
|
|
|
|
elif candidate.confirmation_date:
|
2018-02-02 09:55:09 +01:00
|
|
|
|
messages.error(request, 'Une confirmation a déjà été envoyée!')
|
|
|
|
|
|
elif candidate.canceled_file:
|
|
|
|
|
|
messages.error(request, 'Ce dossier a été annulé!')
|
2018-02-15 12:13:04 +01:00
|
|
|
|
else:
|
|
|
|
|
|
return super().get(request, *args, **kwargs)
|
|
|
|
|
|
return redirect(reverse("admin:candidats_candidate_change", args=(candidate.pk,)))
|
2018-02-02 09:55:09 +01:00
|
|
|
|
|
|
|
|
|
|
def get_initial(self):
|
|
|
|
|
|
initial = super().get_initial()
|
|
|
|
|
|
candidate = Candidate.objects.get(pk=self.kwargs['pk'])
|
|
|
|
|
|
|
|
|
|
|
|
to = [candidate.email]
|
|
|
|
|
|
if candidate.section == 'EDE':
|
|
|
|
|
|
src_email = 'email/candidate_confirm_EDE.txt'
|
2018-06-08 13:50:09 +02:00
|
|
|
|
elif candidate.section == 'EDS':
|
|
|
|
|
|
src_email = 'email/candidate_confirm_EDS.txt'
|
2018-02-15 15:53:12 +01:00
|
|
|
|
elif candidate.section in {'ASA', 'ASE', 'ASSC'}:
|
2018-02-02 09:55:09 +01:00
|
|
|
|
src_email = 'email/candidate_confirm_FE.txt'
|
|
|
|
|
|
if candidate.corporation and candidate.corporation.email:
|
|
|
|
|
|
to.append(candidate.corporation.email)
|
|
|
|
|
|
if candidate.instructor and candidate.instructor.email:
|
|
|
|
|
|
to.append(candidate.instructor.email)
|
|
|
|
|
|
|
|
|
|
|
|
msg_context = {
|
|
|
|
|
|
'candidate': candidate,
|
|
|
|
|
|
'sender': self.request.user,
|
|
|
|
|
|
}
|
|
|
|
|
|
initial.update({
|
|
|
|
|
|
'cci': self.request.user.email,
|
|
|
|
|
|
'to': '; '.join(to),
|
|
|
|
|
|
'subject': "Inscription à la formation {0}".format(candidate.section_option),
|
|
|
|
|
|
'message': loader.render_to_string(src_email, msg_context),
|
|
|
|
|
|
'sender': self.request.user.email,
|
|
|
|
|
|
})
|
|
|
|
|
|
return initial
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-04-12 11:01:45 +02:00
|
|
|
|
class ValidationView(CandidateConfirmationView):
|
|
|
|
|
|
success_message = "Le message de validation a été envoyé pour le candidat {person}"
|
2018-02-02 09:55:09 +01:00
|
|
|
|
candidate_date_field = 'validation_date'
|
|
|
|
|
|
title = "Validation des examens par les enseignant-e-s EDE"
|
|
|
|
|
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
|
|
candidate = Candidate.objects.get(pk=self.kwargs['pk'])
|
|
|
|
|
|
if candidate.validation_date:
|
|
|
|
|
|
messages.error(request, 'Une validation a déjà été envoyée!')
|
|
|
|
|
|
return redirect(reverse("admin:candidats_candidate_change", args=(candidate.pk,)))
|
2018-02-15 15:53:12 +01:00
|
|
|
|
elif not candidate.has_interview:
|
|
|
|
|
|
messages.error(request, "Aucun interview attribué à ce candidat pour l’instant")
|
|
|
|
|
|
return redirect(reverse("admin:candidats_candidate_change", args=(candidate.pk,)))
|
2018-02-02 09:55:09 +01:00
|
|
|
|
return super().get(request, *args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
def get_initial(self):
|
|
|
|
|
|
initial = super().get_initial()
|
|
|
|
|
|
candidate = Candidate.objects.get(pk=self.kwargs['pk'])
|
|
|
|
|
|
|
|
|
|
|
|
msg_context = {
|
|
|
|
|
|
'candidate': candidate,
|
|
|
|
|
|
'sender': self.request.user,
|
|
|
|
|
|
}
|
|
|
|
|
|
initial.update({
|
|
|
|
|
|
'cci': self.request.user.email,
|
|
|
|
|
|
'to': ';'.join([
|
|
|
|
|
|
candidate.interview.teacher_int.email, candidate.interview.teacher_file.email
|
|
|
|
|
|
]),
|
|
|
|
|
|
'subject': "Validation de l'entretien d'admission",
|
|
|
|
|
|
'message': loader.render_to_string('email/validation_enseignant_EDE.txt', msg_context),
|
|
|
|
|
|
'sender': self.request.user.email,
|
|
|
|
|
|
})
|
|
|
|
|
|
return initial
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-04-12 11:01:45 +02:00
|
|
|
|
class ConvocationView(CandidateConfirmationView):
|
|
|
|
|
|
success_message = "Le message de convocation a été envoyé pour le candidat {person}"
|
2018-02-02 09:55:09 +01:00
|
|
|
|
candidate_date_field = 'convocation_date'
|
|
|
|
|
|
title = "Convocation aux examens d'admission EDE"
|
|
|
|
|
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
|
|
candidate = Candidate.objects.get(pk=self.kwargs['pk'])
|
2018-02-15 15:53:12 +01:00
|
|
|
|
if not candidate.has_interview:
|
2018-02-02 09:55:09 +01:00
|
|
|
|
messages.error(request, "Impossible de convoquer sans d'abord définir un interview!")
|
|
|
|
|
|
return redirect(reverse("admin:candidats_candidate_change", args=(candidate.pk,)))
|
|
|
|
|
|
return super().get(request, *args, **kwargs)
|
2018-01-26 18:19:16 +01:00
|
|
|
|
|
2018-02-01 14:39:40 +01:00
|
|
|
|
def get_initial(self):
|
|
|
|
|
|
initial = super().get_initial()
|
2018-01-26 18:19:16 +01:00
|
|
|
|
candidate = Candidate.objects.get(pk=self.kwargs['pk'])
|
2018-02-01 10:47:25 +01:00
|
|
|
|
# Define required documents depending on candidate diploma
|
|
|
|
|
|
common_docs = [
|
2018-01-26 18:19:16 +01:00
|
|
|
|
'registration_form', 'certificate_of_payement', 'police_record', 'cv', 'reflexive_text',
|
2018-02-01 10:47:25 +01:00
|
|
|
|
'has_photo', 'marks_certificate',
|
2018-01-26 18:19:16 +01:00
|
|
|
|
]
|
2018-02-01 10:47:25 +01:00
|
|
|
|
dipl_docs = {
|
|
|
|
|
|
0: [],
|
|
|
|
|
|
1: ['work_certificate'], # CFC ASE
|
|
|
|
|
|
2: ['certif_of_800_childhood', 'work_certificate'],
|
|
|
|
|
|
3: ['certif_of_800_general', 'certif_of_800_childhood', 'work_certificate'],
|
|
|
|
|
|
4: ['certif_of_800_general', 'certif_of_800_childhood', 'work_certificate'],
|
|
|
|
|
|
}[candidate.diploma]
|
|
|
|
|
|
docs_required = dipl_docs + common_docs
|
2018-01-26 18:19:16 +01:00
|
|
|
|
|
|
|
|
|
|
missing_documents = {'documents': ', '.join([
|
2018-02-01 10:47:25 +01:00
|
|
|
|
Candidate._meta.get_field(doc).verbose_name for doc in docs_required
|
|
|
|
|
|
if not getattr(candidate, doc)
|
2018-01-26 18:19:16 +01:00
|
|
|
|
])}
|
|
|
|
|
|
|
|
|
|
|
|
msg_context = {
|
2018-02-14 17:44:30 +01:00
|
|
|
|
'candidate': candidate,
|
2018-01-26 18:19:16 +01:00
|
|
|
|
'candidate_name': " ".join([candidate.civility, candidate.first_name, candidate.last_name]),
|
|
|
|
|
|
'date_lieu_examen': settings.DATE_LIEU_EXAMEN_EDE,
|
|
|
|
|
|
'date_entretien': candidate.interview.date_formatted,
|
|
|
|
|
|
'salle_entretien': candidate.interview.room,
|
|
|
|
|
|
'sender_name': " ".join([self.request.user.first_name, self.request.user.last_name]),
|
|
|
|
|
|
'sender_email': self.request.user.email,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-15 08:56:45 +01:00
|
|
|
|
if missing_documents['documents']:
|
|
|
|
|
|
msg_context['rappel'] = loader.render_to_string('email/rappel_document_EDE.txt', missing_documents)
|
|
|
|
|
|
|
2018-02-01 14:39:40 +01:00
|
|
|
|
initial.update({
|
2018-01-26 18:19:16 +01:00
|
|
|
|
'cci': self.request.user.email,
|
|
|
|
|
|
'to': candidate.email,
|
2018-02-21 14:02:52 +01:00
|
|
|
|
'subject': "Procédure d'admission",
|
2018-01-26 18:19:16 +01:00
|
|
|
|
'message': loader.render_to_string('email/candidate_convocation_EDE.txt', msg_context),
|
|
|
|
|
|
'sender': self.request.user.email,
|
|
|
|
|
|
})
|
2018-02-01 14:39:40 +01:00
|
|
|
|
return initial
|
|
|
|
|
|
|
2018-01-26 18:19:16 +01:00
|
|
|
|
|
2018-02-02 09:55:09 +01:00
|
|
|
|
def inscription_summary(request, pk):
|
|
|
|
|
|
"""
|
|
|
|
|
|
Print a PDF summary of inscription
|
|
|
|
|
|
"""
|
|
|
|
|
|
candidat = Candidate.objects.get(pk=pk)
|
|
|
|
|
|
pdf = InscriptionSummaryPDF(candidat)
|
|
|
|
|
|
pdf.produce(candidat)
|
|
|
|
|
|
|
|
|
|
|
|
with open(pdf.filename, mode='rb') as fh:
|
|
|
|
|
|
response = HttpResponse(fh.read(), content_type='application/pdf')
|
|
|
|
|
|
response['Content-Disposition'] = 'attachment; filename="{0}"'.format(os.path.basename(pdf.filename))
|
|
|
|
|
|
return response
|