From eafe3737dc177c2df4900e5f03d606461b84618a Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 9 Mar 2019 21:22:07 -0600 Subject: [PATCH] Refactor template `content_title()` and prev/next buttons feature those were intertwined but now are a bit more separate, much better --- tailbone/templates/base.mako | 22 +++++++++++++++-- tailbone/templates/master/versions.mako | 2 +- tailbone/templates/master/view.mako | 16 +------------ tailbone/templates/master/view_row.mako | 2 +- tailbone/templates/master/view_version.mako | 16 ------------- tailbone/templates/themes/bobcat/base.mako | 22 +++++++++++++++-- tailbone/views/master.py | 11 +++++++++ tailbone/views/upgrades.py | 26 ++++++++++++++------- 8 files changed, 72 insertions(+), 45 deletions(-) diff --git a/tailbone/templates/base.mako b/tailbone/templates/base.mako index 560db8fb..f06edc91 100644 --- a/tailbone/templates/base.mako +++ b/tailbone/templates/base.mako @@ -83,7 +83,25 @@
- ${self.content_title()} + % if capture(self.content_title): + + % if show_prev_next is not Undefined and show_prev_next: +
+ % if prev_url: + ${h.link_to("« Older", prev_url, class_='button autodisable')} + % else: + ${h.link_to("« Older", '#', class_='button', disabled='disabled')} + % endif + % if next_url: + ${h.link_to("Newer »", next_url, class_='button autodisable')} + % else: + ${h.link_to("Newer »", '#', class_='button', disabled='disabled')} + % endif +
+ % endif + +

${self.content_title()}

+ % endif
@@ -136,7 +154,7 @@ <%def name="title()"> <%def name="content_title()"> -

${self.title()}

+ ${self.title()} <%def name="header_core()"> diff --git a/tailbone/templates/master/versions.mako b/tailbone/templates/master/versions.mako index b6bc3824..b20b7a4e 100644 --- a/tailbone/templates/master/versions.mako +++ b/tailbone/templates/master/versions.mako @@ -18,7 +18,7 @@ <%def name="content_title()"> -

History for ${instance_title}

+ History for ${instance_title} ${grid.render_complete()|n} diff --git a/tailbone/templates/master/view.mako b/tailbone/templates/master/view.mako index 5e7e8c07..2f340e2d 100644 --- a/tailbone/templates/master/view.mako +++ b/tailbone/templates/master/view.mako @@ -26,21 +26,7 @@ <%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 autodisable')} - % 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 autodisable')} - % else: - ${h.link_to(u"Newer »", '#', class_='button', disabled='disabled')} - % endif -
- % endif -

${instance_title}

+ ${instance_title} <%def name="context_menu_items()"> diff --git a/tailbone/templates/master/view_row.mako b/tailbone/templates/master/view_row.mako index 7971444d..e786da05 100644 --- a/tailbone/templates/master/view_row.mako +++ b/tailbone/templates/master/view_row.mako @@ -4,7 +4,7 @@ <%def name="title()">${model_title} <%def name="content_title()"> -

${row_title}

+ ${row_title} <%def name="context_menu_items()"> diff --git a/tailbone/templates/master/view_version.mako b/tailbone/templates/master/view_version.mako index fb9a672e..0980235d 100644 --- a/tailbone/templates/master/view_version.mako +++ b/tailbone/templates/master/view_version.mako @@ -5,22 +5,6 @@ ## TODO: this was basically copied from Revel diff template..need to abstract -<%def name="content_title()"> -
- % if previous_transaction: - ${h.link_to(u"« Older", url('{}.version'.format(route_prefix), uuid=instance.uuid, txnid=previous_transaction.id), class_='button')} - % else: - ${h.link_to(u"« Older", '#', class_='button', disabled='disabled')} - % endif - % if next_transaction: - ${h.link_to(u"Newer »", url('{}.version'.format(route_prefix), uuid=instance.uuid, txnid=next_transaction.id), class_='button')} - % else: - ${h.link_to(u"Newer »", '#', class_='button', disabled='disabled')} - % endif -
-

${self.title()}

- -
diff --git a/tailbone/templates/themes/bobcat/base.mako b/tailbone/templates/themes/bobcat/base.mako index 34495259..d67b390f 100644 --- a/tailbone/templates/themes/bobcat/base.mako +++ b/tailbone/templates/themes/bobcat/base.mako @@ -160,7 +160,25 @@ ## Page Title
- ${self.content_title()} + % if capture(self.content_title): + + % if show_prev_next is not Undefined and show_prev_next: +
+ % if prev_url: + ${h.link_to("« Older", prev_url, class_='button autodisable')} + % else: + ${h.link_to("« Older", '#', class_='button', disabled='disabled')} + % endif + % if next_url: + ${h.link_to("Newer »", next_url, class_='button autodisable')} + % else: + ${h.link_to("Newer »", '#', class_='button', disabled='disabled')} + % endif +
+ % endif + +

${self.content_title()}

+ % endif
@@ -208,7 +226,7 @@ <%def name="title()"> <%def name="content_title()"> -

${self.title()}

+ ${self.title()} <%def name="header_core()"> diff --git a/tailbone/views/master.py b/tailbone/views/master.py index 12e5fe74..460ec850 100644 --- a/tailbone/views/master.py +++ b/tailbone/views/master.py @@ -1041,6 +1041,7 @@ class MasterView(View): """ instance = self.get_instance() model_class = self.get_model_class() + route_prefix = self.get_route_prefix() Transaction = continuum.transaction_class(model_class) transactions = model_transaction_query(self.Session(), instance, model_class, child_classes=self.normalize_version_child_classes()) @@ -1058,6 +1059,13 @@ class MasterView(View): .first() instance_title = self.get_instance_title(instance) + + prev_url = next_url = None + if older: + prev_url = self.request.route_url('{}.version'.format(route_prefix), uuid=instance.uuid, txnid=older.id) + if newer: + next_url = self.request.route_url('{}.version'.format(route_prefix), uuid=instance.uuid, txnid=newer.id) + return self.render_to_response('view_version', { 'instance': instance, 'instance_title': "{} (history)".format(instance_title), @@ -1066,6 +1074,9 @@ class MasterView(View): 'transaction': transaction, 'changed': localtime(self.rattail_config, transaction.issued_at, from_utc=True), 'versions': self.get_relevant_versions(transaction, instance), + 'show_prev_next': True, + 'prev_url': prev_url, + 'next_url': next_url, 'previous_transaction': older, 'next_transaction': newer, 'title_for_version': self.title_for_version, diff --git a/tailbone/views/upgrades.py b/tailbone/views/upgrades.py index 04df5e79..8ab9b959 100644 --- a/tailbone/views/upgrades.py +++ b/tailbone/views/upgrades.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2018 Lance Edgar +# Copyright © 2010-2019 Lance Edgar # # This file is part of Rattail. # @@ -68,7 +68,6 @@ class UpgradeView(MasterView): executable = True execute_progress_template = '/upgrade.mako' execute_progress_initial_msg = "Upgrading" - supports_prev_next = True labels = { 'executed_by': "Executed by", @@ -142,14 +141,25 @@ class UpgradeView(MasterView): def template_kwargs_view(self, **kwargs): upgrade = kwargs['instance'] + + kwargs['show_prev_next'] = True + kwargs['prev_url'] = None + kwargs['next_url'] = None + 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() + older = upgrades.filter(model.Upgrade.created <= upgrade.created)\ + .order_by(model.Upgrade.created.desc())\ + .first() + newer = upgrades.filter(model.Upgrade.created >= upgrade.created)\ + .order_by(model.Upgrade.created)\ + .first() + + if older: + kwargs['prev_url'] = self.get_action_url('view', older) + if newer: + kwargs['next_url'] = self.get_action_url('view', newer) + return kwargs def configure_form(self, f):