Skip to content

Commit

Permalink
Merge pull request #831 from openhealthcare/fix-title
Browse files Browse the repository at this point in the history
Fix title
  • Loading branch information
davidmiller authored Aug 18, 2016
2 parents f1f85ad + 8b5b1c6 commit 509104d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
11 changes: 8 additions & 3 deletions opal/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,18 @@ def _get_field_title(cls, name):
field = cls._meta.get_field(name)

if isinstance(field, models.ManyToOneRel):
return field.related_model._meta.verbose_name_plural.title()
field_name = field.related_model._meta.verbose_name_plural
else:
field_name = field.verbose_name

return field.verbose_name.title()
except FieldDoesNotExist:
# else its foreign key or free text
return getattr(cls, name).verbose_name.title()
field_name = getattr(cls, name).verbose_name

if field_name.islower():
field_name = field_name.title()

return field_name

@classmethod
def build_field_schema(cls):
Expand Down
2 changes: 1 addition & 1 deletion opal/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Dog(lookuplists.LookupList):
class DogOwner(models.EpisodeSubrecord):
name = dmodels.CharField(max_length=200)
dog = fields.ForeignKeyOrFreeText(Dog)
ownership_start_date = dmodels.DateField(blank=True, null=True)
ownership_start_date = dmodels.DateField(blank=True, null=True, verbose_name="OSD")


class HoundOwner(models.EpisodeSubrecord):
Expand Down
5 changes: 5 additions & 0 deletions opal/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,11 @@ def test_verbose_name(self):
only_words = FamousLastWords._get_field_title("words")
self.assertEqual(only_words, "Only Words")

def test_verbose_name_abbreviation(self):
# if a word is an abbreviation already, don't title case it!
osd = DogOwner._get_field_title("ownership_start_date")
self.assertEqual(osd, "OSD")


class BulkUpdateFromDictsTest(OpalTestCase):

Expand Down

0 comments on commit 509104d

Please sign in to comment.