workflows: add jump button option to ignore form errors (#24182)
This commit is contained in:
parent
64ce4e3e1f
commit
3e124dc3f3
|
@ -28,7 +28,7 @@ from wcs.formdef import FormDef
|
|||
from wcs.workflows import (Workflow, EditableWorkflowStatusItem,
|
||||
DisplayMessageWorkflowStatusItem, WorkflowBackofficeFieldsFormDef,
|
||||
ChoiceWorkflowStatusItem, JumpOnSubmitWorkflowStatusItem,
|
||||
SendmailWorkflowStatusItem)
|
||||
SendmailWorkflowStatusItem, CommentableWorkflowStatusItem)
|
||||
from wcs.wf.backoffice_fields import SetBackofficeFieldsWorkflowStatusItem
|
||||
from wcs.wf.export_to_model import ExportToModel, transform_to_pdf
|
||||
from wcs.wf.jump import JumpWorkflowStatusItem
|
||||
|
@ -7025,3 +7025,72 @@ def test_frontoffice_workflow_form_with_impossible_condition(pub):
|
|||
resp = app.get(formdata.get_url(backoffice=False))
|
||||
assert 'f1' not in resp.form.fields
|
||||
assert resp.html.find('div', {'data-field-id': '2'}).attrs.get('style') == 'display: none'
|
||||
|
||||
def test_choice_button_ignore_form_errors(pub):
|
||||
user = create_user(pub)
|
||||
|
||||
formdef = create_formdef()
|
||||
formdef.roles = [logged_users_role().id]
|
||||
formdef.store()
|
||||
|
||||
wf = Workflow(name='status')
|
||||
st1 = wf.add_status('Status1', 'st1')
|
||||
st2 = wf.add_status('Status2', 'st2')
|
||||
|
||||
commentable = CommentableWorkflowStatusItem()
|
||||
commentable.id = '_commentable'
|
||||
commentable.by = [logged_users_role().id]
|
||||
commentable.required = True
|
||||
st1.items.append(commentable)
|
||||
commentable.parent = st1
|
||||
|
||||
choice = ChoiceWorkflowStatusItem()
|
||||
choice.label = 'Submit'
|
||||
choice.by = [logged_users_role().id]
|
||||
choice.id = '_x1'
|
||||
choice.status = st2.id
|
||||
st1.items.append(choice)
|
||||
choice.parent = st1
|
||||
|
||||
choice2 = ChoiceWorkflowStatusItem()
|
||||
choice2.label = 'Submit no check'
|
||||
choice2.by = [logged_users_role().id]
|
||||
choice2.id = '_x2'
|
||||
choice2.status = st2.id
|
||||
choice2.ignore_form_errors = True
|
||||
st1.items.append(choice2)
|
||||
choice2.parent = st1
|
||||
|
||||
wf.store()
|
||||
|
||||
formdef.workflow = wf
|
||||
formdef.store()
|
||||
|
||||
# no comment
|
||||
resp = login(get_app(pub), username='foo', password='foo').get('/test/')
|
||||
resp = resp.form.submit('submit') # -> validation page
|
||||
resp = resp.form.submit('submit') # -> submission
|
||||
resp = resp.follow()
|
||||
|
||||
resp = resp.form.submit('button_x1')
|
||||
assert 'There were errors processing your form.' in resp.body
|
||||
|
||||
# comment
|
||||
resp = login(get_app(pub), username='foo', password='foo').get('/test/')
|
||||
resp = resp.form.submit('submit') # -> validation page
|
||||
resp = resp.form.submit('submit') # -> submission
|
||||
resp = resp.follow()
|
||||
|
||||
resp.form['comment'] = 'plop'
|
||||
resp = resp.form.submit('button_x1').follow()
|
||||
assert '<p>plop</p>' in resp.body
|
||||
assert '<span class="status">Status2' in resp.body
|
||||
|
||||
# no comment but no check
|
||||
resp = login(get_app(pub), username='foo', password='foo').get('/test/')
|
||||
resp = resp.form.submit('submit') # -> validation page
|
||||
resp = resp.form.submit('submit') # -> submission
|
||||
resp = resp.follow()
|
||||
|
||||
resp = resp.form.submit('button_x2').follow()
|
||||
assert '<span class="status">Status2' in resp.body
|
||||
|
|
|
@ -280,7 +280,14 @@ class FormStatusPage(Directory, FormTemplateMixin):
|
|||
|
||||
|
||||
def check_submitted_form(self, form):
|
||||
if form and form.is_submitted() and not form.has_errors():
|
||||
if form and form.is_submitted():
|
||||
submit_button_name = form.get_submit()
|
||||
if submit_button_name:
|
||||
submit_button = form.get_widget(submit_button_name)
|
||||
if getattr(submit_button, 'ignore_form_errors', False):
|
||||
form.clear_errors()
|
||||
if form.has_errors():
|
||||
return
|
||||
url = self.submit(form)
|
||||
if url is None:
|
||||
url = get_request().get_frontoffice_url()
|
||||
|
|
|
@ -2311,6 +2311,7 @@ class ChoiceWorkflowStatusItem(WorkflowStatusJumpItem):
|
|||
by = []
|
||||
backoffice_info_text = None
|
||||
require_confirmation = False
|
||||
ignore_form_errors = False
|
||||
|
||||
def get_label(self):
|
||||
expression = self.get_expression(self.label)
|
||||
|
@ -2347,7 +2348,10 @@ class ChoiceWorkflowStatusItem(WorkflowStatusJumpItem):
|
|||
if self.require_confirmation:
|
||||
get_response().add_javascript(['jquery.js', '../../i18n.js', 'qommon.js'])
|
||||
widget.attrs = {'data-ask-for-confirmation': 'true'}
|
||||
form.get_widget('button%s' % self.id).backoffice_info_text = self.backoffice_info_text
|
||||
widget.backoffice_info_text = self.backoffice_info_text
|
||||
widget.ignore_form_errors = self.ignore_form_errors
|
||||
if self.ignore_form_errors:
|
||||
widget.attrs['formnovalidate'] = 'formnovalidate'
|
||||
|
||||
def submit_form(self, form, formdata, user, evo):
|
||||
if form.get_submit() == 'button%s' % self.id:
|
||||
|
@ -2382,11 +2386,17 @@ class ChoiceWorkflowStatusItem(WorkflowStatusJumpItem):
|
|||
form.add(VarnameWidget, '%sidentifier' % prefix,
|
||||
title=_('Identifier'), value=self.identifier,
|
||||
advanced=True)
|
||||
if 'ignore_form_errors' in parameters:
|
||||
form.add(CheckboxWidget, '%signore_form_errors' % prefix,
|
||||
title=_('Ignore form errors'),
|
||||
value=self.ignore_form_errors,
|
||||
advanced=True)
|
||||
|
||||
def get_parameters(self):
|
||||
return ('label', 'by', 'status',
|
||||
'require_confirmation',
|
||||
'backoffice_info_text',
|
||||
'ignore_form_errors',
|
||||
'set_marker_on_status',
|
||||
'condition', 'identifier',)
|
||||
|
||||
|
|
Loading…
Reference in New Issue