From f0ccab05b3fa19ad6ca0603eacc20308e05cde58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 19 May 2015 17:17:02 +0200 Subject: [PATCH 2/2] forms: add a "preview" mode for disabled forms (#22) --- tests/test_form_pages.py | 24 ++++++++++++++++++++++++ wcs/admin/forms.py | 5 ++++- wcs/formdef.py | 4 +++- wcs/forms/root.py | 12 ++++++++---- wcs/root.py | 4 +++- 5 files changed, 42 insertions(+), 7 deletions(-) diff --git a/tests/test_form_pages.py b/tests/test_form_pages.py index ef0be89..956947e 100644 --- a/tests/test_form_pages.py +++ b/tests/test_form_pages.py @@ -625,3 +625,27 @@ def test_form_count_dispatching(pub): assert len(formdef.data_class().select(clause=lambda x: x.status == 'wf-st2')) == 1 assert len(formdef.data_class().select(clause=lambda x: x.status == 'wf-st1')) == 1 + +def test_preview_form(pub): + user = create_user(pub) + + formdef = create_formdef() + formdef.fields = [] + formdef.disabled = True + formdef.store() + + # check the preview page is not accessible to regular users + get_app(pub).get('/preview/test/', status=403) + + # check it's accessible to admins + user.is_admin = True + user.store() + page = login(get_app(pub), username='foo', password='foo').get('/preview/test/') + + # check no formdata gets stored + next_page = page.forms[0].submit('submit') + assert 'Check values then click submit.' in next_page.body + next_page = next_page.forms[0].submit('submit') + assert next_page.status_int == 302 + assert next_page.location == 'http://example.net/preview/test/' + assert formdef.data_class().count() == 0 diff --git a/wcs/admin/forms.py b/wcs/admin/forms.py index 77fee50..3eecbb5 100644 --- a/wcs/admin/forms.py +++ b/wcs/admin/forms.py @@ -381,7 +381,10 @@ class FormDefPage(Directory): r += htmltext('') r += htmltext('