Skip to content

Commit

Permalink
move logic off the subrecord into the serialisable mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
fredkingham committed Oct 10, 2017
1 parent cceeced commit 754729c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 34 deletions.
8 changes: 2 additions & 6 deletions 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
Expand Down
12 changes: 0 additions & 12 deletions opal/models.py
Expand Up @@ -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 = []
Expand Down
17 changes: 1 addition & 16 deletions opal/tests/test_models.py
Expand Up @@ -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
)

Expand Down Expand Up @@ -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"
Expand Down
17 changes: 17 additions & 0 deletions opal/tests/test_models_mixins.py
Expand Up @@ -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"
Expand Down

0 comments on commit 754729c

Please sign in to comment.