snapshots: add navigation links (#50010)
This commit is contained in:
parent
910fe6597d
commit
e833ab2ba0
|
@ -339,6 +339,25 @@ def test_form_snapshot_browse(pub, formdef_with_history):
|
|||
resp = resp.click(href='%s/view/' % snapshot.id)
|
||||
assert 'This form is readonly' in resp.text
|
||||
assert '<p>%s</p>' % localstrftime(snapshot.timestamp) in resp.text
|
||||
|
||||
assert '<a class="button disabled" href="#">≪</a>' in resp.text
|
||||
assert '<a class="button disabled" href="#"><</a>' in resp.text
|
||||
assert '<a class="button" href="../../%s/view/">></a>' % (snapshot.id - 1) in resp.text
|
||||
assert '<a class="button" href="../../%s/view/">≫</a>' % (snapshot.id - 6) in resp.text
|
||||
|
||||
resp = resp.click(href='../../%s/view/' % (snapshot.id - 1))
|
||||
assert '<a class="button" href="../../%s/view/">≪</a>' % snapshot.id in resp.text
|
||||
assert '<a class="button" href="../../%s/view/"><</a>' % snapshot.id in resp.text
|
||||
assert '<a class="button" href="../../%s/view/">></a>' % (snapshot.id - 2) in resp.text
|
||||
assert '<a class="button" href="../../%s/view/">≫</a>' % (snapshot.id - 6) in resp.text
|
||||
|
||||
resp = resp.click(href='../../%s/view/' % (snapshot.id - 6))
|
||||
assert '<a class="button" href="../../%s/view/">≪</a>' % snapshot.id in resp.text
|
||||
assert '<a class="button" href="../../%s/view/"><</a>' % (snapshot.id - 5) in resp.text
|
||||
assert '<a class="button disabled" href="#">></a>' in resp.text
|
||||
assert '<a class="button disabled" href="#">≫</a>' in resp.text
|
||||
|
||||
resp = resp.click(href='../../%s/view/' % snapshot.id)
|
||||
resp = resp.click('Description')
|
||||
assert resp.form['description'].value == 'this is a description (5)'
|
||||
assert [x[0].name for x in resp.form.fields.values() if x[0].tag == 'button'] == ['cancel']
|
||||
|
|
|
@ -62,4 +62,21 @@ def snapshot_info_block(snapshot):
|
|||
parts.append(misc.localstrftime(snapshot.timestamp))
|
||||
r += htmltext('<br />').join(parts)
|
||||
r += htmltext('</p>')
|
||||
if snapshot.previous or snapshot.next:
|
||||
r += htmltext('<p class="snapshots-navigation">')
|
||||
if snapshot.id != snapshot.first:
|
||||
r += htmltext(' <a class="button" href="../../%s/view/">≪</a>' % (snapshot.first))
|
||||
r += htmltext(' <a class="button" href="../../%s/view/"><</a>' % (snapshot.previous))
|
||||
else:
|
||||
# currently browsing the first snapshot, display links as disabled
|
||||
r += htmltext(' <a class="button disabled" href="#">≪</a>')
|
||||
r += htmltext(' <a class="button disabled" href="#"><</a>')
|
||||
if snapshot.id != snapshot.last:
|
||||
r += htmltext(' <a class="button" href="../../%s/view/">></a>' % (snapshot.next))
|
||||
r += htmltext(' <a class="button" href="../../%s/view/">≫</a>' % (snapshot.last))
|
||||
else:
|
||||
# currently browsing the last snapshot, display links as disabled
|
||||
r += htmltext(' <a class="button disabled" href="#">></a>')
|
||||
r += htmltext(' <a class="button disabled" href="#">≫</a>')
|
||||
r += htmltext('</p>')
|
||||
return r.getvalue()
|
||||
|
|
|
@ -1920,6 +1920,10 @@ ul.snapshots-list .new-day, ul.snapshots-list .has-label {
|
|||
display: block;
|
||||
}
|
||||
|
||||
p.snapshots-navigation {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#sidebar-custom-views .as-data-source {
|
||||
font-weight: normal;
|
||||
}
|
||||
|
|
|
@ -102,6 +102,54 @@ class Snapshot:
|
|||
self._user = UnknownUser()
|
||||
return self._user
|
||||
|
||||
def load_history(self):
|
||||
if not self.instance:
|
||||
self._history = []
|
||||
return
|
||||
history = get_publisher().snapshot_class.select_object_history(self.instance)
|
||||
self._history = [s.id for s in history]
|
||||
|
||||
@property
|
||||
def previous(self):
|
||||
if not hasattr(self, '_history'):
|
||||
self.load_history()
|
||||
|
||||
try:
|
||||
idx = self._history.index(self.id)
|
||||
except ValueError:
|
||||
return None
|
||||
if idx == 0:
|
||||
return None
|
||||
return self._history[idx - 1]
|
||||
|
||||
@property
|
||||
def next(self):
|
||||
if not hasattr(self, '_history'):
|
||||
self.load_history()
|
||||
|
||||
try:
|
||||
idx = self._history.index(self.id)
|
||||
except ValueError:
|
||||
return None
|
||||
try:
|
||||
return self._history[idx + 1]
|
||||
except IndexError:
|
||||
return None
|
||||
|
||||
@property
|
||||
def first(self):
|
||||
if not hasattr(self, '_history'):
|
||||
self.load_history()
|
||||
|
||||
return self._history[0]
|
||||
|
||||
@property
|
||||
def last(self):
|
||||
if not hasattr(self, '_history'):
|
||||
self.load_history()
|
||||
|
||||
return self._history[-1]
|
||||
|
||||
def restore(self, as_new=True):
|
||||
instance = self.instance
|
||||
if as_new:
|
||||
|
|
Loading…
Reference in New Issue