Prevent trying to send validation with candidate without interview

This commit is contained in:
Claude Paroz 2018-02-15 15:53:12 +01:00
parent e8b0f3cf78
commit 127460e352
4 changed files with 21 additions and 13 deletions

View file

@ -15,11 +15,8 @@ class CandidateForm(forms.ModelForm):
fields = '__all__'
def __init__(self, *args, **kwargs):
if kwargs.get('instance'):
try:
kwargs['initial'] = {'interview': kwargs['instance'].interview}
except Interview.DoesNotExist:
pass
if kwargs.get('instance') and kwargs['instance'].has_interview:
kwargs['initial'] = {'interview': kwargs['instance'].interview}
return super().__init__(*args, **kwargs)
def save(self, **kwargs):

View file

@ -150,6 +150,14 @@ class Candidate(models.Model):
else:
return '{0}, option «{1}»'.format(self.get_section_display(), self.get_option_display())
@property
def has_interview(self):
try:
self.interview
return True
except Interview.DoesNotExist:
return False
@property
def total_result(self):
return (self.examination_result or 0) + (self.interview_result or 0) + (self.file_result or 0)

View file

@ -270,11 +270,10 @@ Sans nouvelles de votre part 5 jours ouvrables avant la date du premier examen,
def test_validation_enseignant_ede(self):
self.maxDiff = None
ede = Section.objects.create(name='EDE')
henri = Candidate.objects.create(
first_name='Henri', last_name='Dupond', gender='M', birth_date=date(2000, 5, 15),
street="Rue Neuve 3", pcode='2222', city='Petaouchnok',
section=ede, option='ENF',
section='EDE', option='ENF',
email='henri@example.org', deposite_date=date.today()
)
t1 = Teacher.objects.create(
@ -283,11 +282,14 @@ Sans nouvelles de votre part 5 jours ouvrables avant la date du premier examen,
t2 = Teacher.objects.create(
first_name='Jeanne', last_name='Dubois', abrev="JDU", email="jeanne@example.org"
)
self.client.login(username='me', password='mepassword')
response = self.client.get(reverse('candidate-validation', args=[henri.pk]), follow=True)
self.assertContains(response, "Aucun interview attribué à ce candidat pour linstant")
inter = Interview.objects.create(
date=datetime(2018, 3, 10, 10, 30), room='B103', candidat=henri,
teacher_int=t1, teacher_file=t2,
)
self.client.login(username='me', password='mepassword')
response = self.client.get(reverse('candidate-validation', args=[henri.pk]))
expected_message = """Bonjour,

View file

@ -57,7 +57,7 @@ class ConfirmationView(EmailConfirmationBaseView):
def get(self, request, *args, **kwargs):
candidate = Candidate.objects.get(pk=self.kwargs['pk'])
if candidate.section != 'EDE' and not candidate.section.is_fe():
if candidate.section != 'EDE' and not candidate.section in {'ASA', 'ASE', 'ASSC'}:
messages.error(request, "Ce formulaire n'est disponible que pour les candidats EDE ou FE")
elif candidate.confirmation_date:
messages.error(request, 'Une confirmation a déjà été envoyée!')
@ -74,7 +74,7 @@ class ConfirmationView(EmailConfirmationBaseView):
to = [candidate.email]
if candidate.section == 'EDE':
src_email = 'email/candidate_confirm_EDE.txt'
elif candidate.section.is_fe():
elif candidate.section in {'ASA', 'ASE', 'ASSC'}:
src_email = 'email/candidate_confirm_FE.txt'
if candidate.corporation and candidate.corporation.email:
to.append(candidate.corporation.email)
@ -106,6 +106,9 @@ class ValidationView(EmailConfirmationBaseView):
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,)))
elif not candidate.has_interview:
messages.error(request, "Aucun interview attribué à ce candidat pour linstant")
return redirect(reverse("admin:candidats_candidate_change", args=(candidate.pk,)))
return super().get(request, *args, **kwargs)
def get_initial(self):
@ -136,9 +139,7 @@ class ConvocationView(EmailConfirmationBaseView):
def get(self, request, *args, **kwargs):
candidate = Candidate.objects.get(pk=self.kwargs['pk'])
try:
candidate.interview
except Interview.DoesNotExist:
if not candidate.has_interview:
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)