Projet

Général

Profil

0001-snapshots-add-navigation-links-50010.patch

Lauréline Guérin, 12 janvier 2021 15:40

Télécharger (4,2 ko)

Voir les différences:

Subject: [PATCH] snapshots: add navigation links (#50010)

 tests/test_snapshots.py | 19 ++++++++++++++++
 wcs/admin/utils.py      | 11 ++++++++++
 wcs/snapshots.py        | 48 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 78 insertions(+)
tests/test_snapshots.py
339 339
    resp = resp.click(href='%s/view/' % snapshot.id)
340 340
    assert 'This form is readonly' in resp.text
341 341
    assert '<p>%s</p>' % localstrftime(snapshot.timestamp) in resp.text
342

  
343
    assert 'Lt' not in resp.text
344
    assert 'LT' not in resp.text
345
    assert '<a href="../../6/view/">&GT;</a>' in resp.text
346
    assert '<a href="../../1/view/">&Gt;</a>' in resp.text
347

  
348
    resp = resp.click(href='../../6/view/')
349
    assert '<a href="../../7/view/">&Lt;</a>' in resp.text
350
    assert '<a href="../../7/view/">&LT;</a>' in resp.text
351
    assert '<a href="../../5/view/">&GT;</a>' in resp.text
352
    assert '<a href="../../1/view/">&Gt;</a>' in resp.text
353

  
354
    resp = resp.click(href='../../1/view/')
355
    assert '<a href="../../7/view/">&Lt;</a>' in resp.text
356
    assert '<a href="../../2/view/">&LT;</a>' in resp.text
357
    assert 'GT' not in resp.text
358
    assert 'Gt' not in resp.text
359

  
360
    resp = resp.click(href='../../7/view/')
342 361
    resp = resp.click('Description')
343 362
    assert resp.form['description'].value == 'this is a description (5)'
344 363
    assert [x[0].name for x in resp.form.fields.values() if x[0].tag == 'button'] == ['cancel']
wcs/admin/utils.py
62 62
        parts.append(misc.localstrftime(snapshot.timestamp))
63 63
    r += htmltext('<br />').join(parts)
64 64
    r += htmltext('</p>')
65
    if snapshot.previous or snapshot.next:
66
        r += htmltext('<p>')
67
        if snapshot.id != snapshot.first:
68
            r += htmltext(' <a href="../../%s/view/">&Lt;</a>') % (snapshot.first)
69
        if snapshot.previous:
70
            r += htmltext(' <a href="../../%s/view/">&LT;</a>') % (snapshot.previous)
71
        if snapshot.next:
72
            r += htmltext(' <a href="../../%s/view/">&GT;</a>') % (snapshot.next)
73
        if snapshot.id != snapshot.last:
74
            r += htmltext(' <a href="../../%s/view/">&Gt;</a>') % (snapshot.last)
75
        r += htmltext('</p>')
65 76
    return r.getvalue()
wcs/snapshots.py
102 102
                self._user = UnknownUser()
103 103
        return self._user
104 104

  
105
    def load_history(self):
106
        if not self.instance:
107
            self._history = []
108
            return
109
        history = get_publisher().snapshot_class.select_object_history(self.instance)
110
        self._history = [s.id for s in history]
111

  
112
    @property
113
    def previous(self):
114
        if not hasattr(self, '_history'):
115
            self.load_history()
116

  
117
        try:
118
            idx = self._history.index(self.id)
119
        except ValueError:
120
            return None
121
        if idx == 0:
122
            return None
123
        return self._history[idx - 1]
124

  
125
    @property
126
    def next(self):
127
        if not hasattr(self, '_history'):
128
            self.load_history()
129

  
130
        try:
131
            idx = self._history.index(self.id)
132
        except ValueError:
133
            return None
134
        try:
135
            return self._history[idx + 1]
136
        except IndexError:
137
            return None
138

  
139
    @property
140
    def first(self):
141
        if not hasattr(self, '_history'):
142
            self.load_history()
143

  
144
        return self._history[0]
145

  
146
    @property
147
    def last(self):
148
        if not hasattr(self, '_history'):
149
            self.load_history()
150

  
151
        return self._history[-1]
152

  
105 153
    def restore(self, as_new=True):
106 154
        instance = self.instance
107 155
        if as_new:
108
-