Changed is_examination_valid to missing_examination_data
This commit is contained in:
parent
f019ba4021
commit
9341f906bd
3 changed files with 32 additions and 18 deletions
|
|
@ -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 d’examen est manquante")
|
||||
if not self.room:
|
||||
missing.append("La salle d’examen n’est pas définie")
|
||||
if not self.expert:
|
||||
missing.append("L’expert externe n’est pas défini")
|
||||
if not self.internal_expert:
|
||||
missing.append("L’expert interne n’est pas défini")
|
||||
return missing
|
||||
|
||||
@classmethod
|
||||
def prepare_import(cls, student_values):
|
||||
''' Hook for tabimport, before new object get created '''
|
||||
|
|
|
|||
|
|
@ -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 d’examen est manquante",
|
||||
"La salle d’examen n’est pas définie",
|
||||
"L’expert externe n’est pas défini",
|
||||
"L’expert interne n’est 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")
|
||||
|
|
|
|||
|
|
@ -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 = "L’expert externe n’a pas de courriel valide !"
|
||||
elif not self.student.internal_expert.email:
|
||||
error = "L’expert 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("L’expert externe n’a pas de courriel valide !")
|
||||
if self.student.internal_expert and not self.student.internal_expert.email:
|
||||
errors.append("L’expert 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 à l’expert!")
|
||||
missing = student.missing_examination_data()
|
||||
if missing:
|
||||
messages.error(request, "\n".join(
|
||||
["Toutes les informations ne sont pas disponibles pour la lettre à l’expert!"]
|
||||
+ missing
|
||||
))
|
||||
return redirect(reverse("admin:stages_student_change", args=(student.pk,)))
|
||||
pdf = ExpertEdeLetterPdf(student)
|
||||
pdf.produce()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue