Add prev/next buttons when viewing upgrade details

This commit is contained in:
Lance Edgar 2017-08-13 18:28:40 -05:00
parent 852bafdfa0
commit c0a28716f5
4 changed files with 33 additions and 3 deletions

View file

@ -26,6 +26,24 @@
% endif
</%def>
<%def name="content_title()">
% if master.supports_prev_next:
<div style="float: right;">
% if prev_instance:
${h.link_to(u"« Older", url('{}.view'.format(route_prefix), uuid=prev_instance.uuid), class_='button')}
% else:
${h.link_to(u"« Older", '#', class_='button', disabled='disabled')}
% endif
% if next_instance:
${h.link_to(u"Newer »", url('{}.view'.format(route_prefix), uuid=next_instance.uuid), class_='button')}
% else:
${h.link_to(u"Newer »", '#', class_='button', disabled='disabled')}
% endif
</div>
% endif
<h1>${instance_title}</h1>
</%def>
<%def name="context_menu_items()">
<li>${h.link_to("Permalink for this {}".format(model_title), action_url('view', instance))}</li>
% if master.has_versions and request.rattail_config.versioning_enabled() and request.has_perm('{}.versions'.format(permission_prefix)):

View file

@ -1,8 +1,6 @@
## -*- coding: utf-8; -*-
<%inherit file="tailbone:templates/master/view.mako" />
<%def name="content_title()">
<h1>${instance_title}</h1>
</%def>
## TODO: remove this once it's safe (no callers use it)...
${parent.body()}

View file

@ -75,6 +75,7 @@ class MasterView(View):
executable = False
execute_progress_template = None
execute_progress_initial_msg = None
supports_prev_next = False
supports_mobile = False
mobile_creatable = False

View file

@ -56,6 +56,7 @@ class UpgradeView(MasterView):
executable = True
execute_progress_template = '/upgrade.mako'
execute_progress_initial_msg = "Upgrading"
supports_prev_next = True
labels = {
'executed_by': "Executed by",
@ -127,6 +128,18 @@ class UpgradeView(MasterView):
if upgrade.status_code == self.enum.UPGRADE_STATUS_EXECUTING:
return 'notice'
def template_kwargs_view(self, **kwargs):
upgrade = kwargs['instance']
upgrades = self.Session.query(model.Upgrade)\
.filter(model.Upgrade.uuid != upgrade.uuid)
kwargs['prev_instance'] = upgrades.filter(model.Upgrade.created <= upgrade.created)\
.order_by(model.Upgrade.created.desc())\
.first()
kwargs['next_instance'] = upgrades.filter(model.Upgrade.created >= upgrade.created)\
.order_by(model.Upgrade.created)\
.first()
return kwargs
def configure_form(self, f):
super(UpgradeView, self).configure_form(f)
f.set_enum('status_code', self.enum.UPGRADE_STATUS)