From 5ef320455e0bc51ad06ae9acf63f2643ca6828ba Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Wed, 14 Feb 2018 18:41:57 +0100 Subject: [PATCH] Replaced total_result* fields by a total_result property --- candidats/admin.py | 6 ++---- .../migrations/0009_remove_total_fields.py | 19 +++++++++++++++++++ candidats/models.py | 6 ++++-- candidats/tests.py | 16 ++++++++++++++-- 4 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 candidats/migrations/0009_remove_total_fields.py diff --git a/candidats/admin.py b/candidats/admin.py index bae89f0..24b5f0d 100644 --- a/candidats/admin.py +++ b/candidats/admin.py @@ -45,8 +45,7 @@ class CandidateAdmin(admin.ModelAdmin): list_filter = ('section', 'option') search_fields = ('last_name', 'city') readonly_fields = ( - 'total_result_points', 'total_result_mark', 'confirmation_date', - 'convocation_date', 'candidate_actions', + 'total_result', 'confirmation_date', 'convocation_date', 'candidate_actions', ) actions = [export_candidates] fieldsets = ( @@ -74,8 +73,7 @@ class CandidateAdmin(admin.ModelAdmin): ('promise', 'contract', 'activity_rate'), ('inscr_other_school',), ('interview', 'examination_teacher'), - ('examination_result', 'interview_result', 'file_result', 'total_result_points', - 'total_result_mark'), + ('examination_result', 'interview_result', 'file_result', 'total_result'), ('confirmation_date', 'validation_date', 'convocation_date'), ), }), diff --git a/candidats/migrations/0009_remove_total_fields.py b/candidats/migrations/0009_remove_total_fields.py new file mode 100644 index 0000000..604e601 --- /dev/null +++ b/candidats/migrations/0009_remove_total_fields.py @@ -0,0 +1,19 @@ +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('candidats', '0008_add_examination_teacher'), + ] + + operations = [ + migrations.RemoveField( + model_name='candidate', + name='total_result_mark', + ), + migrations.RemoveField( + model_name='candidate', + name='total_result_points', + ), + ] diff --git a/candidats/models.py b/candidats/models.py index 762e369..fde65aa 100644 --- a/candidats/models.py +++ b/candidats/models.py @@ -109,8 +109,6 @@ class Candidate(models.Model): examination_result = models.PositiveSmallIntegerField('Points examen', blank=True, null=True) interview_result = models.PositiveSmallIntegerField('Points entretien prof.', blank=True, null=True) file_result = models.PositiveSmallIntegerField('Points dossier', blank=True, null=True) - total_result_points = models.PositiveSmallIntegerField('Total points', blank=True, null=True) - total_result_mark = models.PositiveSmallIntegerField('Note finale', blank=True, null=True) inscr_other_school = models.CharField("Inscr. autre école", max_length=30, blank=True) certif_of_800_childhood = models.BooleanField("Attest. 800h. enfance", default=False) @@ -152,6 +150,10 @@ class Candidate(models.Model): else: return '{0}, option «{1}»'.format(self.get_section_display(), self.get_option_display()) + @property + def total_result(self): + return (self.examination_result or 0) + (self.interview_result or 0) + (self.file_result or 0) + def get_ok(self, fieldname): return 'OK' if getattr(self, fieldname) is True else 'NON' diff --git a/candidats/tests.py b/candidats/tests.py index 58ae19c..f0f297d 100644 --- a/candidats/tests.py +++ b/candidats/tests.py @@ -17,9 +17,21 @@ class CandidateTests(TestCase): 'me', 'me@example.org', 'mepassword', first_name='Hans', last_name='Schmid', ) + def test_total_result(self): + ede = Section.objects.create(name='EDE') + cand = Candidate( + first_name='Henri', last_name='Dupond', gender='M', section=ede, + email='henri@example.org', deposite_date=date.today() + ) + self.assertEqual(cand.total_result, 0) + cand.examination_result = 7 + cand.interview_result = 4 + cand.file_result = 5 + self.assertEqual(cand.total_result, 16) + def test_interview(self): inter = Interview.objects.create(date=datetime(2018, 3, 10, 10, 30), room='B103') - self.assertEqual(str(inter), 'samedi 10 mars 2018 à 10h30 : ?/? - (N) -salle:B103-???') + self.assertEqual(str(inter), 'samedi 10 mars 2018 à 10h30 : ? (Ent.) / ? (Dos.) - (N) -salle:B103-???') ede = Section.objects.create(name='EDE') cand = Candidate.objects.create( first_name='Henri', last_name='Dupond', gender='M', section=ede, @@ -33,7 +45,7 @@ class CandidateTests(TestCase): inter.save() self.assertEqual( str(inter), - 'samedi 10 mars 2018 à 10h30 : JCA/JDU - (N) -salle:B103-Dupond Henri' + 'samedi 10 mars 2018 à 10h30 : JCA (Ent.) / JDU (Dos.) - (N) -salle:B103-Dupond Henri' ) self.assertEqual(cand.interview, inter)