From 754729cd3a1f5a783a953ebac8f66a225e5410d4 Mon Sep 17 00:00:00 2001 From: fredkingham Date: Tue, 10 Oct 2017 19:54:47 +0100 Subject: [PATCH] move logic off the subrecord into the serialisable mixin --- doc/docs/reference/mixins.md | 8 ++------ opal/models.py | 12 ------------ opal/tests/test_models.py | 17 +---------------- opal/tests/test_models_mixins.py | 17 +++++++++++++++++ 4 files changed, 20 insertions(+), 34 deletions(-) diff --git a/doc/docs/reference/mixins.md b/doc/docs/reference/mixins.md index 3c6cb2029..271c91f1d 100644 --- a/doc/docs/reference/mixins.md +++ b/doc/docs/reference/mixins.md @@ -1,11 +1,7 @@ ## Opal mixins -### SerialisableFields -Provides the fields that are on the model for example -if we have an allergy model with a field drug -it might serialise like below - - Allergy._get_fieldnames_to_serialize() -> ["id", "drug"] +### Serialisable +Provides the information the display name, icon, api name of the model, along with the fields that should be serialised with the model and their titles (verbose_names) and data types (e.g. date, string). #### build_schema_for_field_name diff --git a/opal/models.py b/opal/models.py index a39c73b1c..1911bb9ec 100644 --- a/opal/models.py +++ b/opal/models.py @@ -929,18 +929,6 @@ def __unicode__(self): def get_api_name(cls): return camelcase_to_underscore(cls._meta.object_name) - @classmethod - def get_icon(cls): - return getattr(cls, '_icon', None) - - @classmethod - def get_display_name(cls): - if hasattr(cls, '_title'): - return cls._title - if cls._meta.verbose_name.islower(): - return cls._meta.verbose_name.title() - return cls._meta.verbose_name - @classmethod def _get_template(cls, template, prefixes=None): template_locations = [] diff --git a/opal/tests/test_models.py b/opal/tests/test_models.py index 958d837ef..a2b515d14 100644 --- a/opal/tests/test_models.py +++ b/opal/tests/test_models.py @@ -18,7 +18,7 @@ from opal.tests import test_patient_lists from opal.tests.models import ( FamousLastWords, PatientColour, ExternalSubRecord, SymptomComplex, - PatientConsultation, Birthday, DogOwner, HatWearer, InvisibleHatWearer, + PatientConsultation, Birthday, DogOwner, HatWearer, HouseOwner, HoundOwner, Colour, FavouriteColour, Dinner ) @@ -248,21 +248,6 @@ def test_get_template_with_prefixes(self, find): ]) self.assertEqual(result, "found") - def test_get_display_name_from_property(self): - self.assertEqual('Wearer of Hats', HatWearer.get_display_name()) - - def test_get_display_name_from_meta_verbose_name(self): - self.assertEqual( - 'Invisible Wearer of Hats', - InvisibleHatWearer.get_display_name() - ) - - def test_get_display_name_from_verbose_name_but_capwords(self): - self.assertEqual( - 'Dog Owner', - DogOwner.get_display_name() - ) - def test_date_time_deserialisation(self): patient, _ = self.new_patient_and_episode_please() birthday_date = "10/1/2000" diff --git a/opal/tests/test_models_mixins.py b/opal/tests/test_models_mixins.py index 25ce79695..9e2db3fef 100644 --- a/opal/tests/test_models_mixins.py +++ b/opal/tests/test_models_mixins.py @@ -59,6 +59,23 @@ def test_get_field_type(self): models.ForeignKey, SerialisableModel._get_field_type('patient_id') ) + def test_get_display_name_from_property(self): + self.assertEqual( + 'Wearer of Hats', test_models.HatWearer.get_display_name() + ) + + def test_get_display_name_from_meta_verbose_name(self): + self.assertEqual( + 'Invisible Wearer of Hats', + test_models.InvisibleHatWearer.get_display_name() + ) + + def test_get_display_name_from_verbose_name_but_capwords(self): + self.assertEqual( + 'Dog Owner', + test_models.DogOwner.get_display_name() + ) + def test_get_description(self): self.assertEqual( SerialisableModel.get_description(), "so this is nice"