From c0a28716f56d20a9dae823235ed3e7e1c771a321 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sun, 13 Aug 2017 18:28:40 -0500 Subject: [PATCH] Add prev/next buttons when viewing upgrade details --- tailbone/templates/master/view.mako | 18 ++++++++++++++++++ .../templates/themes/better/master/view.mako | 4 +--- tailbone/views/master.py | 1 + tailbone/views/upgrades.py | 13 +++++++++++++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/tailbone/templates/master/view.mako b/tailbone/templates/master/view.mako index e50ebd71..6c3fc928 100644 --- a/tailbone/templates/master/view.mako +++ b/tailbone/templates/master/view.mako @@ -26,6 +26,24 @@ % endif +<%def name="content_title()"> + % if master.supports_prev_next: +
+ % 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 +
+ % endif +

${instance_title}

+ + <%def name="context_menu_items()">
  • ${h.link_to("Permalink for this {}".format(model_title), action_url('view', instance))}
  • % if master.has_versions and request.rattail_config.versioning_enabled() and request.has_perm('{}.versions'.format(permission_prefix)): diff --git a/tailbone/templates/themes/better/master/view.mako b/tailbone/templates/themes/better/master/view.mako index 5159a548..455df4d8 100644 --- a/tailbone/templates/themes/better/master/view.mako +++ b/tailbone/templates/themes/better/master/view.mako @@ -1,8 +1,6 @@ ## -*- coding: utf-8; -*- <%inherit file="tailbone:templates/master/view.mako" /> -<%def name="content_title()"> -

    ${instance_title}

    - +## TODO: remove this once it's safe (no callers use it)... ${parent.body()} diff --git a/tailbone/views/master.py b/tailbone/views/master.py index 28e0efd5..c06f1e70 100644 --- a/tailbone/views/master.py +++ b/tailbone/views/master.py @@ -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 diff --git a/tailbone/views/upgrades.py b/tailbone/views/upgrades.py index 9fbc6ac5..de4cb164 100644 --- a/tailbone/views/upgrades.py +++ b/tailbone/views/upgrades.py @@ -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)