diff --git a/candidats/tests.py b/candidats/tests.py index 4566205..bfba54e 100644 --- a/candidats/tests.py +++ b/candidats/tests.py @@ -254,7 +254,6 @@ Sans nouvelles de votre part 5 jours ouvrables avant la date du premier examen, # Now send the message response = self.client.post(reverse('candidate-convocation', args=[henri.pk]), data={ - 'id_candidate': str(henri.pk), 'cci': 'me@example.org', 'to': henri.email, 'subject': "Procédure de qualification", diff --git a/stages/admin.py b/stages/admin.py index c2088b7..5f51737 100644 --- a/stages/admin.py +++ b/stages/admin.py @@ -112,7 +112,7 @@ class StudentAdmin(admin.ModelAdmin): list_filter = (('archived', ArchivedListFilter), ('klass', KlassRelatedListFilter)) search_fields = ('last_name', 'first_name', 'pcode', 'city', 'klass__name') autocomplete_fields = ('corporation', 'instructor', 'supervisor', 'mentor', 'expert') - readonly_fields = ('report_sem1_sent', 'report_sem2_sent', 'examination_actions') + readonly_fields = ('report_sem1_sent', 'report_sem2_sent', 'examination_actions', 'date_soutenance_mailed') fieldsets = ( (None, { 'fields': (('last_name', 'first_name', 'ext_id'), ('street', 'pcode', 'city', 'district'), @@ -133,6 +133,7 @@ class StudentAdmin(admin.ModelAdmin): ('training_referent', 'referent', 'mentor'), ('internal_expert', 'expert'), ('session', 'date_exam', 'room', 'mark'), + ('date_soutenance_mailed', 'date_confirm_received'), ('examination_actions',) ) }), diff --git a/stages/migrations/0012_added_date_fields_for_student.py b/stages/migrations/0012_added_date_fields_for_student.py new file mode 100644 index 0000000..ad4063b --- /dev/null +++ b/stages/migrations/0012_added_date_fields_for_student.py @@ -0,0 +1,21 @@ +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('stages', '0011_complement_corpcontact_fields'), + ] + + operations = [ + migrations.AddField( + model_name='student', + name='date_confirm_received', + field=models.DateTimeField(blank=True, null=True, verbose_name='Récept. confirm'), + ), + migrations.AddField( + model_name='student', + name='date_soutenance_mailed', + field=models.DateTimeField(blank=True, null=True, verbose_name='Convoc. env.'), + ), + ] diff --git a/stages/models.py b/stages/models.py index 650b9e6..b6b3ae5 100644 --- a/stages/models.py +++ b/stages/models.py @@ -260,8 +260,9 @@ class Student(models.Model): last_appointment = models.DateField(blank=True, null=True) room = models.CharField('Salle', max_length=15, blank=True) mark = models.DecimalField('Note', max_digits=3, decimal_places=2, blank=True, null=True) + date_soutenance_mailed = models.DateTimeField("Convoc. env.", blank=True, null=True) + date_confirm_received = models.DateTimeField("Récept. confirm", blank=True, null=True) # ============== Fields for examination ====================== - support_tabimport = True class Meta: diff --git a/stages/tests.py b/stages/tests.py index 1f4705a..45f1c29 100644 --- a/stages/tests.py +++ b/stages/tests.py @@ -40,7 +40,8 @@ class StagesTest(TestCase): ) Student.objects.bulk_create([ Student(first_name="Albin", last_name="Dupond", birth_date="1994-05-12", - pcode="2300", city="La Chaux-de-Fonds", klass=klass1), + pcode="2300", city="La Chaux-de-Fonds", email="albin@example.org", + klass=klass1), Student(first_name="Justine", last_name="Varrin", birth_date="1994-07-12", pcode="2000", city="Neuchâtel", klass=klass1), Student(first_name="Elvire", last_name="Hickx", birth_date="1994-05-20", @@ -191,6 +192,17 @@ me@example.org tél. 032 886 33 00 """ self.assertEqual(response.context['form'].initial['message'], expected_message) + # Now send the message + response = self.client.post(url, data={ + 'cci': 'me@example.org', + 'to': st.email, + 'subject': "Convocation", + 'message': "Monsieur Albin, ...", + 'sender': 'me@example.org', + }) + self.assertEqual(len(mail.outbox), 1) + st.refresh_from_db() + self.assertIsNotNone(st.date_soutenance_mailed) def test_print_letter_ede_expert(self): st = Student.objects.get(first_name="Albin") diff --git a/stages/views.py b/stages/views.py index bfd9518..9e13ef6 100644 --- a/stages/views.py +++ b/stages/views.py @@ -668,9 +668,8 @@ class EmailConfirmationView(EmailConfirmationBaseView): class StudentConvocationExaminationView(EmailConfirmationView): success_message = "Le message de convocation a été envoyé pour l’étudiant {person}" title = "Convocation à la soutenance du travail de diplôme" - candidate_date_field = 'convocation_date' - def get(self, request, *args, **kwargs): + def dispatch(self, request, *args, **kwargs): self.student = Student.objects.get(pk=self.kwargs['pk']) error = '' if not self.student.is_examination_valid: @@ -682,7 +681,7 @@ class StudentConvocationExaminationView(EmailConfirmationView): if error: messages.error(request, error) return redirect(reverse("admin:stages_student_change", args=(self.student.pk,))) - return super().get(request, *args, **kwargs) + return super().dispatch(request, *args, **kwargs) def get_initial(self): initial = super().get_initial() @@ -730,6 +729,10 @@ class StudentConvocationExaminationView(EmailConfirmationView): }) return initial + def on_success(self, student): + student.date_soutenance_mailed = timezone.now() + student.save() + EXPORT_FIELDS = [ # Student fields