Skip to content

Commit

Permalink
Merge pull request #174 from nyaruka/read_title_tweak
Browse files Browse the repository at this point in the history
Allow all views to override title using title field
  • Loading branch information
rowanseymour authored Aug 15, 2023
2 parents 4f1470d + ddc8004 commit d9df08f
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions smartmin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,9 @@ def get_queryset(self):

def derive_title(self):
"""
By default we just return the string representation of our object
Fallback to the string representation of our object
"""
return str(self.object)
return self.title if self.title is not None else str(self.object)

def derive_fields(self):
"""
Expand Down Expand Up @@ -531,9 +531,9 @@ def derive_title(self):
"""
Derives our title from our list
"""
title = super(SmartListView, self).derive_title()
title = super().derive_title()

if not title:
if title is None:
return force_str(self.model._meta.verbose_name_plural).title()
else:
return title
Expand Down Expand Up @@ -808,10 +808,7 @@ def derive_title(self):
"""
Derives our title from our object
"""
if not self.title:
return _("Form")
else:
return self.title
return self.title if self.title is not None else _("Form")

def derive_success_message(self):
"""
Expand Down Expand Up @@ -1070,7 +1067,7 @@ def derive_title(self):
"""
Derives our title from our object
"""
if not self.title:
if self.title is None:
return _("Edit %s") % force_str(self.model._meta.verbose_name).title()
else:
return self.title
Expand Down Expand Up @@ -1285,7 +1282,7 @@ def derive_title(self):
"""
Derives our title from our object
"""
if not self.title:
if self.title is None:
return _("Create %s") % force_str(self.model._meta.verbose_name).title()
else:
return self.title
Expand Down

0 comments on commit d9df08f

Please sign in to comment.