Add 'index title' setting to master view

This was needed due to a new way of showing the index link when
e.g. viewing a record, particularly with regard to messaging and a new
template design.
This commit is contained in:
Lance Edgar 2016-05-01 12:34:15 -05:00
parent c9afae3a44
commit f3cab67aaf
2 changed files with 24 additions and 5 deletions

View file

@ -296,6 +296,13 @@ class MasterView(View):
"""
return self.request.route_url(self.get_route_prefix())
@classmethod
def get_index_title(cls):
"""
Returns the title for the index page.
"""
return getattr(cls, 'index_title', cls.get_model_title_plural())
def get_action_url(self, action, instance):
"""
Generate a URL for the given action on the given instance.
@ -317,6 +324,7 @@ class MasterView(View):
'model_title_plural': self.get_model_title_plural(),
'route_prefix': self.get_route_prefix(),
'permission_prefix': self.get_permission_prefix(),
'index_title': self.get_index_title(),
'index_url': self.get_index_url(),
'action_url': self.get_action_url,
}

View file

@ -128,6 +128,18 @@ class MessagesView(MasterView):
replying = False
reply_header_sent_format = '%a %d %b %Y at %I:%M %p'
def get_index_title(self):
if self.listing:
return self.index_title
if self.viewing:
message = self.get_instance()
recipient = self.get_recipient(message)
if recipient and recipient.status == enum.MESSAGE_STATUS_ARCHIVE:
return "Message Archive"
elif not recipient:
return "Sent Messages"
return "Message Inbox"
def get_index_url(self):
# not really used, but necessary to make certain other code happy
return self.request.route_url('messages.inbox')
@ -344,11 +356,7 @@ class MessagesView(MasterView):
Move a message, either to the archive or back to the inbox.
"""
message = self.get_instance()
recipient = None
for recip in message.recipients:
if recip.recipient is self.request.user:
recipient = recip
break
recipient = self.get_recipient(message)
if not recipient:
raise httpexceptions.HTTPForbidden
@ -414,6 +422,7 @@ class InboxView(MessagesView):
"""
url_prefix = '/messages/inbox'
grid_key = 'messages.inbox'
index_title = "Message Inbox"
def get_index_url(self):
return self.request.route_url('messages.inbox')
@ -429,6 +438,7 @@ class ArchiveView(MessagesView):
"""
url_prefix = '/messages/archive'
grid_key = 'messages.archive'
index_title = "Message Archive"
def get_index_url(self):
return self.request.route_url('messages.archive')
@ -445,6 +455,7 @@ class SentView(MessagesView):
url_prefix = '/messages/sent'
grid_key = 'messages.sent'
checkboxes = False
index_title = "Sent Messages"
def get_index_url(self):
return self.request.route_url('messages.sent')