0001-backoffice-make-it-possible-to-remove-backoffice-sub.patch
tests/test_backoffice_pages.py | ||
---|---|---|
880 | 880 |
# check it kept the same id |
881 | 881 |
assert resp.location == 'http://example.net/backoffice/management/form-title/%s/' % formdata_no |
882 | 882 | |
883 |
def test_backoffice_submission_remove_drafts(pub): |
|
884 |
user = create_user(pub) |
|
885 |
create_environment(pub) |
|
886 | ||
887 |
app = login(get_app(pub)) |
|
888 | ||
889 |
formdef = FormDef.get_by_urlname('form-title') |
|
890 |
formdef.enable_tracking_codes = True |
|
891 |
formdef.backoffice_submission_roles = user.roles[:] |
|
892 |
formdef.store() |
|
893 |
data_class = formdef.data_class() |
|
894 |
data_class.wipe() |
|
895 |
pub.tracking_code_class.wipe() |
|
896 |
resp = app.get('/backoffice/submission/') |
|
897 |
assert formdef.url_name in resp.body |
|
898 | ||
899 |
resp = resp.click(formdef.name) |
|
900 |
resp.form['f1'] = 'test submission' |
|
901 |
resp.form['f2'] = 'baz' |
|
902 |
resp.form['f3'] = 'C' |
|
903 |
resp = resp.form.submit('submit') |
|
904 |
assert 'Check values then click submit.' in resp.body |
|
905 | ||
906 |
assert data_class.count() == 1 |
|
907 |
formdata = data_class.select()[0] |
|
908 |
formdata_no = formdata.id |
|
909 |
tracking_code = data_class.select()[0].tracking_code |
|
910 | ||
911 |
# stop here, go back to the index |
|
912 |
resp = app.get('/backoffice/submission/') |
|
913 |
resp = resp.click('#%s' % formdata_no) |
|
914 |
resp = resp.follow() |
|
915 | ||
916 |
# and try to delete the form (but cancel) |
|
917 |
resp = resp.click('Delete') |
|
918 |
resp = resp.form.submit('cancel') |
|
919 |
assert resp.location == 'http://example.net/backoffice/submission/' |
|
920 |
assert data_class.count() == 1 |
|
921 |
assert pub.tracking_code_class().count() == 1 |
|
922 | ||
923 |
# and this time for real |
|
924 |
resp = app.get('/backoffice/submission/') |
|
925 |
resp = resp.click('#%s' % formdata_no) |
|
926 |
resp = resp.follow() |
|
927 |
resp = resp.click('Delete') |
|
928 |
resp = resp.form.submit('delete') |
|
929 |
assert resp.location == 'http://example.net/backoffice/submission/' |
|
930 |
assert data_class.count() == 0 |
|
931 |
assert pub.tracking_code_class().count() == 0 |
|
932 | ||
933 |
# check it's not possible to delete an actual formdata |
|
934 |
formdata = data_class() |
|
935 |
formdata.store() |
|
936 |
resp = app.get('/backoffice/submission/form-title/remove/%s' % formdata.id, |
|
937 |
status=403) |
|
938 | ||
883 | 939 |
def test_backoffice_submission_sections(pub): |
884 | 940 |
user = create_user(pub) |
885 | 941 |
create_environment(pub) |
wcs/backoffice/submission.py | ||
---|---|---|
19 | 19 |
from quixote.html import TemplateIO, htmltext |
20 | 20 | |
21 | 21 |
from qommon.backoffice.menu import html_top |
22 |
from qommon.form import * |
|
22 | 23 |
from qommon import errors, misc |
23 | 24 | |
24 | 25 |
from wcs.formdef import FormDef |
... | ... | |
26 | 27 |
from wcs.forms.root import FormPage as PublicFormFillPage |
27 | 28 | |
28 | 29 | |
30 |
class RemoveDraftDirectory(Directory): |
|
31 |
def __init__(self, parent_directory): |
|
32 |
self.parent_directory = parent_directory |
|
33 |
self.formdef = parent_directory.formdef |
|
34 | ||
35 |
def _q_lookup(self, component): |
|
36 |
try: |
|
37 |
formdata = self.formdef.data_class().get(component) |
|
38 |
except KeyError: |
|
39 |
raise errors.TraversalError() |
|
40 |
if not formdata.is_draft(): |
|
41 |
raise errors.AccessForbiddenError() |
|
42 |
if not formdata.backoffice_submission: |
|
43 |
raise errors.AccessForbiddenError() |
|
44 | ||
45 |
self.parent_directory.check_role() |
|
46 |
if self.parent_directory.edit_mode: |
|
47 |
raise errors.AccessForbiddenError() |
|
48 | ||
49 |
self.parent_directory.html_top(title=_('Remove')) |
|
50 | ||
51 |
form = Form(enctype='multipart/form-data') |
|
52 |
form.widgets.append(HtmlWidget('<p>%s</p>' % _( |
|
53 |
'You are about to irrevocably delete this form.'))) |
|
54 |
form.add_submit('delete', _('Delete')) |
|
55 |
form.add_submit('cancel', _('Cancel')) |
|
56 |
if form.get_widget('cancel').parse(): |
|
57 |
return redirect('../..') |
|
58 |
if not form.is_submitted() or form.has_errors(): |
|
59 |
r = TemplateIO(html=True) |
|
60 |
r += htmltext('<h2>%s</h2>') % (_('Deleting Form')) |
|
61 |
r += form.render() |
|
62 |
return r.getvalue() |
|
63 | ||
64 |
if formdata.tracking_code: |
|
65 |
tracking_code = get_publisher().tracking_code_class.get(formdata.tracking_code) |
|
66 |
tracking_code.remove_self() |
|
67 |
formdata.remove_self() |
|
68 |
return redirect('../..') |
|
69 | ||
70 | ||
29 | 71 |
class FormFillPage(PublicFormFillPage): |
72 |
_q_exports = ['', 'tempfile', 'autosave', 'code', |
|
73 |
('remove', 'remove_draft')] |
|
74 | ||
75 |
def __init__(self, *args, **kwargs): |
|
76 |
super(FormFillPage, self).__init__(*args, **kwargs) |
|
77 |
self.remove_draft = RemoveDraftDirectory(self) |
|
78 | ||
30 | 79 |
def html_top(self, *args, **kwargs): |
31 | 80 |
return html_top('submission', *args, **kwargs) |
32 | 81 | |
... | ... | |
60 | 109 |
from .management import FormBackOfficeStatusPage |
61 | 110 |
r += FormBackOfficeStatusPage(self.formdef, formdata).get_extra_context_bar() |
62 | 111 | |
112 |
if formdata and not self.edit_mode: |
|
113 |
r += htmltext('<div><p>') |
|
114 |
r += htmltext('<a rel="popup" href="remove/%s">%s</a>') % (formdata.id, _('Delete')) |
|
115 |
r += htmltext('</p></div>') |
|
116 | ||
63 | 117 |
return r.getvalue() |
64 | 118 | |
65 | 119 |
def form_side(self, step_no, page_no=0, log_detail=None, data=None): |
66 |
- |