Changed is_examination_valid to missing_examination_data

This commit is contained in:
Claude Paroz 2018-04-24 09:22:43 +02:00
parent f019ba4021
commit 9341f906bd
3 changed files with 32 additions and 18 deletions

View file

@ -304,10 +304,6 @@ class Student(models.Model):
else:
return {'M': 'étudiant', 'F': 'étudiante'}.get(self.gender, '')
@property
def is_examination_valid(self):
return (self.date_exam and self.room and self.expert and self.internal_expert)
def save(self, **kwargs):
if self.archived and not self.archived_text:
# Fill archived_text with training data, JSON-formatted
@ -326,6 +322,18 @@ class Student(models.Model):
age_m = int((age - age_y) * 12)
return '%d ans%s' % (age_y, ' %d m.' % age_m if age_m > 0 else '')
def missing_examination_data(self):
missing = []
if not self.date_exam:
missing.append("La date dexamen est manquante")
if not self.room:
missing.append("La salle dexamen nest pas définie")
if not self.expert:
missing.append("Lexpert externe nest pas défini")
if not self.internal_expert:
missing.append("Lexpert interne nest pas défini")
return missing
@classmethod
def prepare_import(cls, student_values):
''' Hook for tabimport, before new object get created '''

View file

@ -158,7 +158,11 @@ class StagesTest(TestCase):
self.client.login(username='me', password='mepassword')
url = reverse('student-ede-convocation', args=[st.pk])
response = self.client.get(url, follow=True)
self.assertContains(response, "Toutes les informations ne sont pas disponibles pour la convocation!")
for err in ("La date dexamen est manquante",
"La salle dexamen nest pas définie",
"Lexpert externe nest pas défini",
"Lexpert interne nest pas défini"):
self.assertContains(response, err)
st.date_exam = datetime(2018, 6, 28, 12, 00)
st.room = "B123"
st.expert = CorpContact.objects.get(last_name="Horner")

View file

@ -671,17 +671,15 @@ class StudentConvocationExaminationView(EmailConfirmationView):
def dispatch(self, request, *args, **kwargs):
self.student = Student.objects.get(pk=self.kwargs['pk'])
error = ''
if not self.student.is_examination_valid:
error = "Toutes les informations ne sont pas disponibles pour la convocation!"
elif not self.student.expert.email:
error = "Lexpert externe na pas de courriel valide !"
elif not self.student.internal_expert.email:
error = "Lexpert interne n'a pas de courriel valide !"
elif self.student.date_soutenance_mailed is not None:
error = "Une convocation a déjà été envoyée !"
if error:
messages.error(request, error)
errors = self.student.missing_examination_data()
if self.student.expert and not self.student.expert.email:
errors.append("Lexpert externe na pas de courriel valide !")
if self.student.internal_expert and not self.student.internal_expert.email:
errors.append("Lexpert interne n'a pas de courriel valide !")
if self.student.date_soutenance_mailed is not None:
errors.append("Une convocation a déjà été envoyée !")
if errors:
messages.error(request, "\n".join(errors))
return redirect(reverse("admin:stages_student_change", args=(self.student.pk,)))
return super().dispatch(request, *args, **kwargs)
@ -919,8 +917,12 @@ def print_expert_ede_compensation_form(request, pk):
travail de diplôme
"""
student = Student.objects.get(pk=pk)
if not student.is_examination_valid:
messages.error(request, "Toutes les informations ne sont pas disponibles pour la lettre à lexpert!")
missing = student.missing_examination_data()
if missing:
messages.error(request, "\n".join(
["Toutes les informations ne sont pas disponibles pour la lettre à lexpert!"]
+ missing
))
return redirect(reverse("admin:stages_student_change", args=(student.pk,)))
pdf = ExpertEdeLetterPdf(student)
pdf.produce()