Refactor template content_title() and prev/next buttons feature

those were intertwined but now are a bit more separate, much better
This commit is contained in:
Lance Edgar 2019-03-09 21:22:07 -06:00
parent 9f743daf07
commit eafe3737dc
8 changed files with 72 additions and 45 deletions

View file

@ -83,7 +83,25 @@
</div><!-- global -->
<div class="page">
${self.content_title()}
% if capture(self.content_title):
% if show_prev_next is not Undefined and show_prev_next:
<div style="float: right;">
% 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
</div>
% endif
<h1>${self.content_title()}</h1>
% endif
</div>
</header>
@ -136,7 +154,7 @@
<%def name="title()"></%def>
<%def name="content_title()">
<h1>${self.title()}</h1>
${self.title()}
</%def>
<%def name="header_core()">

View file

@ -18,7 +18,7 @@
</%def>
<%def name="content_title()">
<h1>History for ${instance_title}</h1>
History for ${instance_title}
</%def>
${grid.render_complete()|n}

View file

@ -26,21 +26,7 @@
</%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 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
</div>
% endif
<h1>${instance_title}</h1>
${instance_title}
</%def>
<%def name="context_menu_items()">

View file

@ -4,7 +4,7 @@
<%def name="title()">${model_title}</%def>
<%def name="content_title()">
<h1>${row_title}</h1>
${row_title}
</%def>
<%def name="context_menu_items()">

View file

@ -5,22 +5,6 @@
## TODO: this was basically copied from Revel diff template..need to abstract
<%def name="content_title()">
<div style="float: right;">
% 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
</div>
<h1>${self.title()}</h1>
</%def>
<div class="form-wrapper">
<div class="form">

View file

@ -160,7 +160,25 @@
## Page Title
<section id="content-title" class="hero is-primary">
<div class="container">
${self.content_title()}
% if capture(self.content_title):
% if show_prev_next is not Undefined and show_prev_next:
<div style="float: right;">
% 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
</div>
% endif
<h1 class="title">${self.content_title()}</h1>
% endif
</div>
</section>
@ -208,7 +226,7 @@
<%def name="title()"></%def>
<%def name="content_title()">
<h1 class="title">${self.title()}</h1>
${self.title()}
</%def>
<%def name="header_core()">

View file

@ -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,

View file

@ -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)\
older = upgrades.filter(model.Upgrade.created <= upgrade.created)\
.order_by(model.Upgrade.created.desc())\
.first()
kwargs['next_instance'] = upgrades.filter(model.Upgrade.created >= upgrade.created)\
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):