0001-forms-add-a-preview-mode-for-disabled-forms-22.patch
tests/test_admin_pages.py | ||
---|---|---|
186 | 186 | |
187 | 187 |
# try changing title |
188 | 188 |
resp = app.get('/backoffice/forms/1/') |
189 |
resp = resp.click(href='title')
|
|
189 |
resp = resp.click('change title')
|
|
190 | 190 |
assert resp.forms[0]['name'].value == 'form title' |
191 | 191 |
resp.forms[0]['name'] = 'new title' |
192 | 192 |
resp = resp.forms[0].submit() |
tests/test_form_pages.py | ||
---|---|---|
675 | 675 | |
676 | 676 |
assert len(formdef.data_class().select(clause=lambda x: x.status == 'wf-st2')) == 1 |
677 | 677 |
assert len(formdef.data_class().select(clause=lambda x: x.status == 'wf-st1')) == 1 |
678 | ||
679 |
def test_preview_form(pub): |
|
680 |
user = create_user(pub) |
|
681 | ||
682 |
formdef = create_formdef() |
|
683 |
formdef.data_class().wipe() |
|
684 |
formdef.fields = [] |
|
685 |
formdef.disabled = True |
|
686 |
formdef.store() |
|
687 | ||
688 |
# check the preview page is not accessible to regular users |
|
689 |
get_app(pub).get('/preview/test/', status=403) |
|
690 | ||
691 |
# check it's accessible to admins |
|
692 |
user.is_admin = True |
|
693 |
user.store() |
|
694 |
page = login(get_app(pub), username='foo', password='foo').get('/preview/test/') |
|
695 | ||
696 |
# check no formdata gets stored |
|
697 |
next_page = page.forms[0].submit('submit') |
|
698 |
assert 'Check values then click submit.' in next_page.body |
|
699 |
next_page = next_page.forms[0].submit('submit') |
|
700 |
assert next_page.status_int == 302 |
|
701 |
assert next_page.location == 'http://example.net/preview/test/' |
|
702 |
assert formdef.data_class().count() == 0 |
wcs/admin/forms.py | ||
---|---|---|
382 | 382 |
r += htmltext('</ul>') |
383 | 383 | |
384 | 384 |
r += htmltext('<ul>') |
385 |
if not self.formdef.is_disabled(): |
|
385 |
if self.formdef.is_disabled(): |
|
386 |
r += htmltext('<li><a href="%s">%s</a></li>') % ( |
|
387 |
self.formdef.get_url(preview=True), _('Preview Online')) |
|
388 |
else: |
|
386 | 389 |
r += htmltext('<li><a href="%s">%s</a></li>') % ( |
387 | 390 |
self.formdef.get_url(), _('Display Online')) |
388 | 391 |
r += htmltext('<li><a href="public-url" rel="popup">%s</a></li>') % _('Display public URL') |
wcs/formdef.py | ||
---|---|---|
329 | 329 |
return cls.get_on_index(url_name, 'url_name', ignore_migration=ignore_migration) |
330 | 330 |
get_by_urlname = classmethod(get_by_urlname) |
331 | 331 | |
332 |
def get_url(self, backoffice = False):
|
|
332 |
def get_url(self, backoffice=False, preview=False):
|
|
333 | 333 |
if backoffice: |
334 | 334 |
base_url = get_publisher().get_backoffice_url() + '/management' |
335 |
elif preview: |
|
336 |
base_url = get_publisher().get_frontoffice_url() + '/preview' |
|
335 | 337 |
else: |
336 | 338 |
base_url = get_publisher().get_frontoffice_url() |
337 | 339 |
return '%s/%s/' % (base_url, self.url_name) |
wcs/forms/preview.py | ||
---|---|---|
1 |
# w.c.s. - web application for online forms |
|
2 |
# Copyright (C) 2005-2015 Entr'ouvert |
|
3 |
# |
|
4 |
# This program is free software; you can redistribute it and/or modify |
|
5 |
# it under the terms of the GNU General Public License as published by |
|
6 |
# the Free Software Foundation; either version 2 of the License, or |
|
7 |
# (at your option) any later version. |
|
8 |
# |
|
9 |
# This program is distributed in the hope that it will be useful, |
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
# GNU General Public License for more details. |
|
13 |
# |
|
14 |
# You should have received a copy of the GNU General Public License |
|
15 |
# along with this program; if not, see <http://www.gnu.org/licenses/>. |
|
16 | ||
17 |
from quixote import get_publisher, redirect |
|
18 |
from quixote.directory import Directory, AccessControlled |
|
19 |
from qommon import errors |
|
20 | ||
21 |
from .root import FormPage |
|
22 | ||
23 | ||
24 |
class PreviewFormPage(FormPage): |
|
25 |
_q_exports = [''] |
|
26 | ||
27 |
def check_role(self): |
|
28 |
pass |
|
29 | ||
30 |
def check_disabled(self): |
|
31 |
return False |
|
32 | ||
33 |
def submitted(self, *args, **kwargs): |
|
34 |
return redirect('.') |
|
35 | ||
36 | ||
37 |
class PreviewDirectory(AccessControlled, Directory): |
|
38 |
def _q_access(self): |
|
39 |
if not get_publisher().get_backoffice_root().is_accessible('forms'): |
|
40 |
raise errors.AccessForbiddenError() |
|
41 | ||
42 |
def _q_lookup(self, component): |
|
43 |
return PreviewFormPage(component) |
wcs/forms/root.py | ||
---|---|---|
437 | 437 |
formdata.status = str('') |
438 | 438 |
get_publisher().substitutions.feed(formdata) |
439 | 439 | |
440 |
def _q_index(self, log_detail = None, editing = None): |
|
441 |
self.check_role() |
|
440 |
def check_disabled(self): |
|
442 | 441 |
if self.formdef.is_disabled(): |
443 | 442 |
if self.formdef.disabled_redirection: |
444 |
url = misc.get_variadic_url(self.formdef.disabled_redirection,
|
|
443 |
return misc.get_variadic_url(self.formdef.disabled_redirection,
|
|
445 | 444 |
get_publisher().substitutions.get_context_variables()) |
446 |
return redirect(url) |
|
447 | 445 |
else: |
448 | 446 |
raise errors.AccessForbiddenError() |
447 |
return False |
|
448 | ||
449 |
def _q_index(self, log_detail = None, editing = None): |
|
450 |
self.check_role() |
|
451 |
if self.check_disabled(): |
|
452 |
return redirect(self.check_disabled()) |
|
449 | 453 | |
450 | 454 |
session = get_session() |
451 | 455 |
wcs/root.py | ||
---|---|---|
51 | 51 |
from roles import Role |
52 | 52 |
from wcs.api import get_user_from_api_query_string, ApiDirectory |
53 | 53 |
from myspace import MyspaceDirectory |
54 |
from forms.preview import PreviewDirectory |
|
54 | 55 | |
55 | 56 | |
56 | 57 |
class CompatibilityDirectory(Directory): |
... | ... | |
194 | 195 |
_q_exports = ['admin', 'backoffice', 'forms', 'login', 'logout', 'token', 'saml', |
195 | 196 |
'ident', 'register', 'afterjobs', 'themes', 'myspace', 'user', 'roles', |
196 | 197 |
'pages', ('tmp-upload', 'tmp_upload'), 'api', '__version__', |
197 |
'tryauth', 'auth'] |
|
198 |
'tryauth', 'auth', 'preview']
|
|
198 | 199 | |
199 | 200 |
api = ApiDirectory() |
200 | 201 |
themes = template.ThemesDirectory() |
... | ... | |
380 | 381 |
register = RegisterDirectory() |
381 | 382 |
ident = IdentDirectory() |
382 | 383 |
afterjobs = AfterJobStatusDirectory() |
384 |
preview = PreviewDirectory() |
|
383 |
- |