0001-snapshots-add-label-comment-timestamp-and-user-in-si.patch
tests/test_snapshots.py | ||
---|---|---|
12 | 12 |
from wcs.data_sources import NamedDataSource |
13 | 13 |
from wcs.formdef import FormDef |
14 | 14 |
from wcs.qommon.form import UploadedFile |
15 |
from wcs.qommon.misc import localstrftime |
|
15 | 16 |
from wcs.workflows import Workflow |
16 | 17 |
from wcs.workflows import ExportToModel |
17 | 18 |
from wcs.wscalls import NamedWsCall |
... | ... | |
236 | 237 |
resp = app.get('/backoffice/forms/blocks/%s/history/' % blockdef.id) |
237 | 238 |
snapshot = pub.snapshot_class.select_object_history(blockdef)[0] |
238 | 239 |
resp = resp.click(href='%s/view/' % snapshot.id) |
239 |
assert 'This block of fields is readonly.' in resp |
|
240 |
assert 'This block of fields is readonly.' in resp.text |
|
241 |
assert '<p>%s</p>' % localstrftime(snapshot.timestamp) in resp.text |
|
240 | 242 | |
241 | 243 | |
242 | 244 |
def test_card_snapshot_browse(pub): |
... | ... | |
274 | 276 |
resp = app.get('/backoffice/cards/%s/history/' % carddef.id) |
275 | 277 |
snapshot = pub.snapshot_class.select_object_history(carddef)[0] |
276 | 278 |
resp = resp.click(href='%s/view/' % snapshot.id) |
277 |
assert 'This card model is readonly' in resp |
|
279 |
assert 'This card model is readonly' in resp.text |
|
280 |
assert '<p>%s</p>' % localstrftime(snapshot.timestamp) in resp.text |
|
278 | 281 |
resp = resp.click('Geolocation') |
279 | 282 |
assert [x[0].name for x in resp.form.fields.values() if x[0].tag == 'button'] == ['cancel'] |
280 | 283 |
assert pub.custom_view_class.count() == 0 # custom views are not restore on preview |
... | ... | |
299 | 302 |
resp = app.get('/backoffice/forms/data-sources/%s/history/' % datasource.id) |
300 | 303 |
snapshot = pub.snapshot_class.select_object_history(datasource)[0] |
301 | 304 |
resp = resp.click(href='%s/view/' % snapshot.id) |
302 |
assert 'This data source is readonly' in resp |
|
305 |
assert 'This data source is readonly' in resp.text |
|
306 |
assert '<p>%s</p>' % localstrftime(snapshot.timestamp) in resp.text |
|
303 | 307 |
with pytest.raises(IndexError): |
304 | 308 |
resp = resp.click('Edit') |
305 | 309 | |
... | ... | |
333 | 337 |
resp = app.get('/backoffice/forms/%s/history/' % formdef_with_history.id) |
334 | 338 |
snapshot = pub.snapshot_class.select_object_history(formdef_with_history)[0] |
335 | 339 |
resp = resp.click(href='%s/view/' % snapshot.id) |
336 |
assert 'This form is readonly' in resp |
|
340 |
assert 'This form is readonly' in resp.text |
|
341 |
assert '<p>%s</p>' % localstrftime(snapshot.timestamp) in resp.text |
|
337 | 342 |
resp = resp.click('Description') |
338 | 343 |
assert resp.form['description'].value == 'this is a description (5)' |
339 | 344 |
assert [x[0].name for x in resp.form.fields.values() if x[0].tag == 'button'] == ['cancel'] |
... | ... | |
357 | 362 |
resp = app.get('/backoffice/workflows/%s/history/' % workflow.id) |
358 | 363 |
snapshot = pub.snapshot_class.select_object_history(workflow)[0] |
359 | 364 |
resp = resp.click(href='%s/view/' % snapshot.id) |
360 |
assert 'This workflow is readonly' in resp |
|
365 |
assert 'This workflow is readonly' in resp.text |
|
366 |
assert '<p>%s</p>' % localstrftime(snapshot.timestamp) in resp.text |
|
361 | 367 | |
362 | 368 | |
363 | 369 |
def test_workflow_with_model_snapshot_browse(pub): |
... | ... | |
397 | 403 |
resp = app.get('/backoffice/workflows/%s/history/' % workflow.id) |
398 | 404 |
snapshot = pub.snapshot_class.select_object_history(workflow)[0] |
399 | 405 |
resp = resp.click(href='%s/view/' % snapshot.id) |
400 |
assert 'This workflow is readonly' in resp |
|
406 |
assert 'This workflow is readonly' in resp.text
|
|
401 | 407 |
assert len(os.listdir(os.path.join(pub.app_dir, 'models'))) == 3 + i |
402 | 408 | |
403 | 409 | |
... | ... | |
418 | 424 |
resp = app.get('/backoffice/settings/wscalls/%s/history/' % wscall.id) |
419 | 425 |
snapshot = pub.snapshot_class.select_object_history(wscall)[0] |
420 | 426 |
resp = resp.click(href='%s/view/' % snapshot.id) |
421 |
assert 'This webservice call is readonly' in resp |
|
427 |
assert 'This webservice call is readonly' in resp.text |
|
428 |
assert '<p>%s</p>' % localstrftime(snapshot.timestamp) in resp.text |
|
422 | 429 |
with pytest.raises(IndexError): |
423 | 430 |
resp = resp.click('Edit') |
424 | 431 |
wcs/admin/data_sources.py | ||
---|---|---|
20 | 20 |
from quixote.directory import Directory |
21 | 21 |
from quixote.html import TemplateIO, htmltext |
22 | 22 | |
23 |
from wcs.admin import utils |
|
23 | 24 |
from wcs.qommon import _, force_str |
24 | 25 |
from wcs.qommon import errors, template |
25 | 26 |
from wcs.qommon.form import * |
... | ... | |
207 | 208 |
r = TemplateIO(html=True) |
208 | 209 |
if self.datasource.is_readonly(): |
209 | 210 |
r += htmltext('<div class="infonotice"><p>%s</p></div>') % _('This data source is readonly.') |
211 |
r += utils.snapshot_info_block(snapshot=self.datasource.snapshot_object) |
|
210 | 212 |
r += htmltext('<ul id="sidebar-actions">') |
211 | 213 |
if not self.datasource.is_readonly(): |
212 | 214 |
r += htmltext('<li><a href="delete" rel="popup">%s</a></li>') % _('Delete') |
wcs/admin/fields.py | ||
---|---|---|
22 | 22 |
from quixote.directory import Directory |
23 | 23 |
from quixote.html import TemplateIO, htmltext, htmlescape |
24 | 24 | |
25 |
from wcs.admin import utils |
|
25 | 26 |
from wcs.qommon import _ |
26 | 27 |
from wcs.qommon.form import * |
27 | 28 |
from wcs.qommon import errors, misc |
... | ... | |
337 | 338 |
r += htmltext('</ul>') |
338 | 339 | |
339 | 340 |
if self.objectdef.is_readonly(): |
340 |
get_response().filter['sidebar'] = '<div class="infonotice"><p>%s</p></div>' % _(self.readonly_message) |
|
341 |
get_response().filter['sidebar'] = htmltext('<div class="infonotice"><p>%s</p></div>') % _(self.readonly_message) |
|
342 |
get_response().filter['sidebar'] += utils.snapshot_info_block(snapshot=self.objectdef.snapshot_object) |
|
341 | 343 |
else: |
342 | 344 |
get_response().filter['sidebar'] = str(self.get_new_field_form(self.page_id)) |
343 | 345 |
r += self.index_bottom() |
wcs/admin/forms.py | ||
---|---|---|
673 | 673 |
r = TemplateIO(html=True) |
674 | 674 |
if self.formdef.is_readonly(): |
675 | 675 |
r += htmltext('<div class="infonotice"><p>%s</p></div>') % _('This form is readonly.') |
676 |
r += utils.snapshot_info_block(snapshot=self.formdef.snapshot_object) |
|
676 | 677 |
return r.getvalue() |
677 | 678 |
r += htmltext('<ul id="sidebar-actions">') |
678 | 679 |
r += htmltext('<li><a href="delete" rel="popup">%s</a></li>') % _('Delete') |
wcs/admin/utils.py | ||
---|---|---|
46 | 46 |
r += htmltext('</p>') |
47 | 47 | |
48 | 48 |
return r.getvalue() |
49 | ||
50 | ||
51 |
def snapshot_info_block(snapshot): |
|
52 |
r = TemplateIO(html=True) |
|
53 |
r += htmltext('<p>') |
|
54 |
parts = [] |
|
55 |
if snapshot.label: |
|
56 |
parts.append(htmltext('<strong>%s</strong>') % snapshot.label) |
|
57 |
elif snapshot.comment: |
|
58 |
parts.append(snapshot.comment) |
|
59 |
if snapshot.user_id: |
|
60 |
parts.append('%s (%s)' % (misc.localstrftime(snapshot.timestamp), snapshot.user)) |
|
61 |
else: |
|
62 |
parts.append(misc.localstrftime(snapshot.timestamp)) |
|
63 |
r += htmltext('<br />').join(parts) |
|
64 |
r += htmltext('</p>') |
|
65 |
return r.getvalue() |
wcs/admin/workflows.py | ||
---|---|---|
1585 | 1585 |
r += htmltext('</p>') |
1586 | 1586 |
elif self.workflow.is_readonly(): |
1587 | 1587 |
r += htmltext('<div class="infonotice"><p>%s</p></div>') % _('This workflow is readonly.') |
1588 |
r += utils.snapshot_info_block(snapshot=self.workflow.snapshot_object) |
|
1588 | 1589 |
return r.getvalue() |
1589 | 1590 | |
1590 | 1591 |
r += htmltext('<ul id="sidebar-actions">') |
wcs/admin/wscalls.py | ||
---|---|---|
20 | 20 |
from quixote.directory import Directory |
21 | 21 |
from quixote.html import TemplateIO, htmltext |
22 | 22 | |
23 |
from wcs.admin import utils |
|
23 | 24 |
from wcs.qommon import _, errors, template |
24 | 25 |
from wcs.qommon import misc |
25 | 26 |
from wcs.qommon.form import * |
... | ... | |
112 | 113 |
r = TemplateIO(html=True) |
113 | 114 |
if self.wscall.is_readonly(): |
114 | 115 |
r += htmltext('<div class="infonotice"><p>%s</p></div>') % _('This webservice call is readonly.') |
116 |
r += utils.snapshot_info_block(snapshot=self.wscall.snapshot_object) |
|
115 | 117 |
r += htmltext('<ul id="sidebar-actions">') |
116 | 118 |
if not self.wscall.is_readonly(): |
117 | 119 |
r += htmltext('<li><a href="export">%s</a></li>') % _('Export') |
wcs/backoffice/cards.py | ||
---|---|---|
208 | 208 |
r = TemplateIO(html=True) |
209 | 209 |
if self.formdef.is_readonly(): |
210 | 210 |
r += htmltext('<div class="infonotice"><p>%s</p></div>') % _('This card model is readonly.') |
211 |
r += utils.snapshot_info_block(snapshot=self.formdef.snapshot_object) |
|
211 | 212 |
return r.getvalue() |
212 | 213 |
r += htmltext('<ul id="sidebar-actions">') |
213 | 214 |
r += htmltext('<li><a href="delete" rel="popup">%s</a></li>') % _('Delete') |
wcs/snapshots.py | ||
---|---|---|
88 | 88 |
include_id=True, |
89 | 89 |
snapshot=True) |
90 | 90 |
self._instance.readonly = True |
91 |
self._instance.snapshot_object = self |
|
91 | 92 |
return self._instance |
92 | 93 | |
93 | 94 |
@property |
94 |
- |