fields: move composite widgets out of advanced when apply is clicked (#6727)

This commit is contained in:
Frédéric Péters 2015-03-19 15:46:01 +01:00
parent 45d666464c
commit 4962adb525
2 changed files with 72 additions and 5 deletions

View File

@ -605,6 +605,62 @@ def test_form_edit_field():
assert FormDef.get(1).fields[0].label == 'changed field'
assert FormDef.get(1).fields[0].required == False
def test_form_edit_field_advanced():
create_superuser()
create_role()
FormDef.wipe()
formdef = FormDef()
formdef.name = 'form title'
formdef.fields = [fields.StringField(id='1', label='1st field', type='string')]
formdef.store()
app = login(get_app(pub))
resp = app.get('/admin/forms/1/')
resp = resp.click(href='fields/')
assert '1st field' in resp.body
resp = resp.click('Edit', href='1/')
assert resp.forms[0]['label'].value == '1st field'
assert '<legend>Additional parameters</legend>' in resp.body
assert '<label for="form_prefill">Prefill</label>' in resp.body
# hceck the "prefill" field is under additional parameters
assert resp.body.index('<legend>Additional parameters</legend>') < \
resp.body.index('<label for="form_prefill">Prefill</label>')
# start filling the "prefill" field
resp.forms[0]['prefill$type'] = 'String'
resp = resp.forms[0].submit('prefill$apply')
# it should now appear before the additional parameters section
assert resp.body.index('<legend>Additional parameters</legend>') > \
resp.body.index('<label for="form_prefill">Prefill</label>')
# complete it
resp.forms[0]['prefill$value'] = 'test'
resp = resp.forms[0].submit('submit')
assert resp.location == 'http://example.net/admin/forms/1/fields/'
resp = resp.follow()
assert FormDef.get(formdef.id).fields[0].prefill == {'type': 'string', 'value': 'test'}
# do the same with 'data sources' field
resp = resp.click('Edit', href='1/')
assert resp.forms[0]['label'].value == '1st field'
assert '<legend>Additional parameters</legend>' in resp.body
assert '<label for="form_data_source">External Data Source</label>' in resp.body
# hceck the "data source" field is under additional parameters
assert resp.body.index('<legend>Additional parameters</legend>') < \
resp.body.index('<label for="form_data_source">External Data Source</label>')
# start filling the "data source" field
resp.forms[0]['data_source$type'] = 'JSON URL'
resp = resp.forms[0].submit('data_source$apply')
# it should now appear before the additional parameters section
assert resp.body.index('<legend>Additional parameters</legend>') > \
resp.body.index('<label for="form_data_source">External Data Source</label>')
def test_workflows():
app = login(get_app(pub))
app.get('/admin/workflows/')

View File

@ -344,9 +344,14 @@ class WidgetField(Field):
value = self.in_listing, advanced=True)
form.add(StringWidget, 'extra_css_class', title = _('Extra class for CSS styling'),
value=self.extra_css_class, size=30, advanced=(not self.extra_css_class))
prefill_in_advanced = (not self.prefill or self.prefill.get('type') == 'none')
if prefill_in_advanced and (get_request().form.get('prefill$apply') or
get_request().form.get('prefill$value')):
# check if the apply button has been clicked, and get the field out
# of the "advanced parameters" section if that's the case.
prefill_in_advanced = False
form.add(PrefillSelectionWidget, 'prefill', title = _('Prefill'),
value=self.prefill,
advanced=(not self.prefill or self.prefill.get('type') == 'none'),
value=self.prefill, advanced=prefill_in_advanced,
**self.prefill_kwargs)
def check_admin_form(self, form):
@ -471,6 +476,12 @@ class CommentField(Field):
register_field_class(CommentField)
def is_datasource_advanced(value):
data_source_in_advanced = (not value)
if data_source_in_advanced and (get_request().form.get('data_source$apply') or
get_request().form.get('data_source$value')):
data_source_in_advanced = False
return data_source_in_advanced
class StringField(WidgetField):
@ -499,7 +510,7 @@ class StringField(WidgetField):
value=self.data_source,
title=_('External Data Source'),
hint=_('This will allow autocompletion from an external source.'),
advanced=(not self.data_source),
advanced=is_datasource_advanced(self.data_source),
required=False)
def get_admin_attributes(self):
@ -924,7 +935,7 @@ class ItemField(WidgetField):
title=_('External Data Source'),
hint=_('This will get the available items from an external source.'),
required=False,
advanced=not(self.data_source))
advanced=is_datasource_advanced(self.data_source))
def get_admin_attributes(self):
return WidgetField.get_admin_attributes(self) + ['items', 'show_as_radio', 'data_source']
@ -999,7 +1010,7 @@ class ItemsField(WidgetField):
title=_('External Data Source'),
hint=_('This will get the available items from an external source.'),
required=False,
advanced=not(self.data_source))
advanced=is_datasource_advanced(self.data_source))
def get_admin_attributes(self):
return WidgetField.get_admin_attributes(self) + ['items',