Projet

Général

Profil

0001-snapshots-fix-navigation-links-on-fields-page-57319.patch

Lauréline Guérin, 28 septembre 2021 17:05

Télécharger (4,17 ko)

Voir les différences:

Subject: [PATCH] snapshots: fix navigation links on fields page (#57319)

 tests/test_snapshots.py |  8 ++++++++
 wcs/admin/fields.py     |  2 +-
 wcs/admin/utils.py      | 19 ++++++++++++++-----
 3 files changed, 23 insertions(+), 6 deletions(-)
tests/test_snapshots.py
401 401
    assert [x[0].name for x in resp.form.fields.values() if x[0].tag == 'button'] == ['cancel']
402 402
    assert pub.custom_view_class.count() == 0  # custom views are not restore on preview
403 403

  
404
    resp = app.get('/backoffice/forms/%s/history/' % formdef_with_history.id)
405
    resp = resp.click(href='%s/view/' % (snapshot.id - 1))
406
    resp = resp.click(href='fields/')
407
    assert '<a class="button" href="../../../%s/view/fields/">&Lt;</a>' % snapshot.id in resp.text
408
    assert '<a class="button" href="../../../%s/view/fields/">&LT;</a>' % snapshot.id in resp.text
409
    assert '<a class="button" href="../../../%s/view/fields/">&GT;</a>' % (snapshot.id - 2) in resp.text
410
    assert '<a class="button" href="../../../%s/view/fields/">&Gt;</a>' % (snapshot.id - 6) in resp.text
411

  
404 412

  
405 413
def test_form_snapshot_browse_with_import_error(pub):
406 414
    create_superuser(pub)
wcs/admin/fields.py
351 351
            )
352 352
            if hasattr(self.objectdef, 'snapshot_object'):
353 353
                get_response().filter['sidebar'] += utils.snapshot_info_block(
354
                    snapshot=self.objectdef.snapshot_object
354
                    snapshot=self.objectdef.snapshot_object, url_prefix='../../../', url_suffix='fields/'
355 355
                )
356 356
        else:
357 357
            get_response().filter['sidebar'] = str(self.get_new_field_form(self.page_id))
wcs/admin/utils.py
47 47
    return r.getvalue()
48 48

  
49 49

  
50
def snapshot_info_block(snapshot):
50
def snapshot_info_block(snapshot, url_prefix='../../', url_suffix=''):
51 51
    r = TemplateIO(html=True)
52 52
    r += htmltext('<p>')
53 53
    parts = []
......
64 64
    if snapshot.previous or snapshot.next:
65 65
        r += htmltext('<p class="snapshots-navigation">')
66 66
        if snapshot.id != snapshot.first:
67
            r += htmltext(' <a class="button" href="../../%s/view/">&Lt;</a>' % (snapshot.first))
68
            r += htmltext(' <a class="button" href="../../%s/view/">&LT;</a>' % (snapshot.previous))
67
            r += htmltext(
68
                ' <a class="button" href="%s%s/view/%s">&Lt;</a>' % (url_prefix, snapshot.first, url_suffix)
69
            )
70
            r += htmltext(
71
                ' <a class="button" href="%s%s/view/%s">&LT;</a>'
72
                % (url_prefix, snapshot.previous, url_suffix)
73
            )
69 74
        else:
70 75
            # currently browsing the first snapshot, display links as disabled
71 76
            r += htmltext(' <a class="button disabled" href="#">&Lt;</a>')
72 77
            r += htmltext(' <a class="button disabled" href="#">&LT;</a>')
73 78
        if snapshot.id != snapshot.last:
74
            r += htmltext(' <a class="button" href="../../%s/view/">&GT;</a>' % (snapshot.next))
75
            r += htmltext(' <a class="button" href="../../%s/view/">&Gt;</a>' % (snapshot.last))
79
            r += htmltext(
80
                ' <a class="button" href="%s%s/view/%s">&GT;</a>' % (url_prefix, snapshot.next, url_suffix)
81
            )
82
            r += htmltext(
83
                ' <a class="button" href="%s%s/view/%s">&Gt;</a>' % (url_prefix, snapshot.last, url_suffix)
84
            )
76 85
        else:
77 86
            # currently browsing the last snapshot, display links as disabled
78 87
            r += htmltext(' <a class="button disabled" href="#">&GT;</a>')
79
-