Projet

Général

Profil

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

Lauréline Guérin, 19 janvier 2021 14:41

Télécharger (5,76 ko)

Voir les différences:

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

 tests/test_snapshots.py              | 19 +++++++++++
 wcs/admin/utils.py                   | 15 +++++++++
 wcs/qommon/static/css/dc2/admin.scss |  4 +++
 wcs/snapshots.py                     | 48 ++++++++++++++++++++++++++++
 4 files changed, 86 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 '<a class="button disabled" href="../../%s/view/">&Lt;</a>' % snapshot.id in resp.text
344
    assert '<a class="button disabled" href="../../%s/view/">&LT;</a>' % snapshot.id in resp.text
345
    assert '<a class="button" href="../../%s/view/">&GT;</a>' % (snapshot.id - 1) in resp.text
346
    assert '<a class="button" href="../../%s/view/">&Gt;</a>' % (snapshot.id - 6) in resp.text
347

  
348
    resp = resp.click(href='../../%s/view/' % (snapshot.id - 1))
349
    assert '<a class="button" href="../../%s/view/">&Lt;</a>' % snapshot.id in resp.text
350
    assert '<a class="button" href="../../%s/view/">&LT;</a>' % snapshot.id in resp.text
351
    assert '<a class="button" href="../../%s/view/">&GT;</a>' % (snapshot.id - 2) in resp.text
352
    assert '<a class="button" href="../../%s/view/">&Gt;</a>' % (snapshot.id - 6) in resp.text
353

  
354
    resp = resp.click(href='../../%s/view/' % (snapshot.id - 6))
355
    assert '<a class="button" href="../../%s/view/">&Lt;</a>' % snapshot.id in resp.text
356
    assert '<a class="button" href="../../%s/view/">&LT;</a>' % (snapshot.id - 5) in resp.text
357
    assert '<a class="button disabled" href="../../%s/view/">&GT;</a>' % (snapshot.id - 6) in resp.text
358
    assert '<a class="button disabled" href="../../%s/view/">&Gt;</a>' % (snapshot.id - 6) in resp.text
359

  
360
    resp = resp.click(href='../../%s/view/' % snapshot.id)
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 class="snapshots-navigation">')
67
        if snapshot.id != snapshot.first:
68
            r += htmltext(' <a class="button" href="../../%s/view/">&Lt;</a>' % (snapshot.first))
69
            r += htmltext(' <a class="button" href="../../%s/view/">&LT;</a>' % (snapshot.previous))
70
        else:
71
            r += htmltext(' <a class="button disabled" href="../../%s/view/">&Lt;</a>' % (snapshot.first))
72
            r += htmltext(' <a class="button disabled" href="../../%s/view/">&LT;</a>' % (snapshot.first))
73
        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))
76
        else:
77
            r += htmltext(' <a class="button disabled" href="../../%s/view/">&GT;</a>' % (snapshot.last))
78
            r += htmltext(' <a class="button disabled" href="../../%s/view/">&Gt;</a>' % (snapshot.last))
79
        r += htmltext('</p>')
65 80
    return r.getvalue()
wcs/qommon/static/css/dc2/admin.scss
1920 1920
	display: block;
1921 1921
}
1922 1922

  
1923
p.snapshots-navigation {
1924
       text-align: center;
1925
}
1926

  
1923 1927
#sidebar-custom-views .as-data-source {
1924 1928
	font-weight: normal;
1925 1929
}
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
-