backoffice: factor our function to get field types option list (#43824)
This commit is contained in:
parent
ee26182d89
commit
2e03360702
|
@ -1157,7 +1157,7 @@ def test_form_new_field(pub):
|
|||
assert 'There are not yet any fields for this form' in resp.text
|
||||
|
||||
resp.forms[0]['label'] = 'foobar'
|
||||
resp.forms[0]['type'] = 'Text (line)'
|
||||
resp.forms[0]['type'] = 'string'
|
||||
resp = resp.forms[0].submit()
|
||||
assert resp.location == 'http://example.net/backoffice/forms/1/fields/'
|
||||
resp = resp.follow()
|
||||
|
@ -1170,7 +1170,7 @@ def test_form_new_field(pub):
|
|||
|
||||
# add a title too
|
||||
resp.forms[0]['label'] = 'baz'
|
||||
resp.forms[0]['type'] = 'Title'
|
||||
resp.forms[0]['type'] = 'title'
|
||||
resp = resp.forms[0].submit()
|
||||
assert resp.location == 'http://example.net/backoffice/forms/1/fields/'
|
||||
resp = resp.follow()
|
||||
|
@ -1285,7 +1285,7 @@ def test_form_duplicate_file_field(pub):
|
|||
|
||||
# add a first field
|
||||
resp.forms[0]['label'] = 'foobar'
|
||||
resp.forms[0]['type'] = 'File Upload'
|
||||
resp.forms[0]['type'] = 'file'
|
||||
resp = resp.forms[0].submit()
|
||||
assert resp.location == 'http://example.net/backoffice/forms/%s/fields/' % formdef.id
|
||||
resp = resp.follow()
|
||||
|
@ -1640,7 +1640,7 @@ def test_form_edit_page_field(pub):
|
|||
assert 'There are not yet any fields for this form' in resp.text
|
||||
|
||||
resp.forms[0]['label'] = 'foobar'
|
||||
resp.forms[0]['type'] = 'Page'
|
||||
resp.forms[0]['type'] = 'page'
|
||||
resp = resp.forms[0].submit()
|
||||
assert resp.location == 'http://example.net/backoffice/forms/1/fields/'
|
||||
resp = resp.follow()
|
||||
|
@ -1720,7 +1720,7 @@ def test_form_edit_comment_field(pub):
|
|||
# check a new field is created with label as HTML, enclosing label in <p>
|
||||
resp = app.get('/backoffice/forms/1/fields/')
|
||||
resp.forms[0]['label'] = 'foobar'
|
||||
resp.forms[0]['type'] = 'Comment'
|
||||
resp.forms[0]['type'] = 'comment'
|
||||
resp = resp.forms[0].submit()
|
||||
assert resp.location == 'http://example.net/backoffice/forms/1/fields/'
|
||||
assert FormDef.get(formdef.id).fields[-1].label == '<p>foobar</p>'
|
||||
|
@ -1728,7 +1728,7 @@ def test_form_edit_comment_field(pub):
|
|||
# unless label is already given as HTML
|
||||
resp = app.get('/backoffice/forms/1/fields/')
|
||||
resp.forms[0]['label'] = '<div>blah</div>'
|
||||
resp.forms[0]['type'] = 'Comment'
|
||||
resp.forms[0]['type'] = 'comment'
|
||||
resp = resp.forms[0].submit()
|
||||
assert resp.location == 'http://example.net/backoffice/forms/1/fields/'
|
||||
assert FormDef.get(formdef.id).fields[-1].label == '<div>blah</div>'
|
||||
|
@ -3013,7 +3013,7 @@ def test_workflows_edit_display_form_action(pub):
|
|||
resp = resp.click('Edit Fields')
|
||||
|
||||
resp.form['label'] = 'foobar'
|
||||
resp.form['type'] = 'Text (line)'
|
||||
resp.form['type'] = 'string'
|
||||
resp = resp.form.submit()
|
||||
|
||||
resp = resp.follow()
|
||||
|
@ -3201,7 +3201,7 @@ def test_workflows_variables(pub):
|
|||
|
||||
# add a simple field
|
||||
resp.forms[0]['label'] = 'foobar'
|
||||
resp.forms[0]['type'] = 'Text (line)'
|
||||
resp.forms[0]['type'] = 'string'
|
||||
resp = resp.forms[0].submit()
|
||||
assert resp.location == 'http://example.net/backoffice/workflows/1/variables/fields/'
|
||||
resp = resp.follow()
|
||||
|
@ -3287,7 +3287,7 @@ def test_workflows_backoffice_fields(pub):
|
|||
|
||||
# add a simple field
|
||||
resp.forms[0]['label'] = 'foobar'
|
||||
resp.forms[0]['type'] = 'Text (line)'
|
||||
resp.forms[0]['type'] = 'string'
|
||||
resp = resp.forms[0].submit()
|
||||
assert resp.location == 'http://example.net/backoffice/workflows/1/backoffice-fields/fields/'
|
||||
resp = resp.follow()
|
||||
|
@ -3324,7 +3324,7 @@ def test_workflows_backoffice_fields(pub):
|
|||
assert resp.location == 'http://example.net/backoffice/workflows/1/backoffice-fields/fields/'
|
||||
resp = resp.follow()
|
||||
resp.forms[0]['label'] = 'foobar2'
|
||||
resp.forms[0]['type'] = 'Text (line)'
|
||||
resp.forms[0]['type'] = 'string'
|
||||
resp = resp.forms[0].submit()
|
||||
assert resp.location == 'http://example.net/backoffice/workflows/1/backoffice-fields/fields/'
|
||||
resp = resp.follow()
|
||||
|
@ -3340,7 +3340,7 @@ def test_workflows_backoffice_fields(pub):
|
|||
# add a title field
|
||||
resp = app.get('/backoffice/workflows/1/backoffice-fields/fields/')
|
||||
resp.forms[0]['label'] = 'foobar3'
|
||||
resp.forms[0]['type'] = 'Title'
|
||||
resp.forms[0]['type'] = 'title'
|
||||
resp = resp.form.submit()
|
||||
workflow = Workflow.get(workflow.id)
|
||||
assert len(workflow.backoffice_fields_formdef.fields) == 3
|
||||
|
@ -4780,7 +4780,7 @@ def test_settings_user(pub):
|
|||
|
||||
# add a comment field
|
||||
resp.forms[2]['label'] = 'barfoo'
|
||||
resp.forms[2]['type'] = 'Comment'
|
||||
resp.forms[2]['type'] = 'comment'
|
||||
resp = resp.forms[2].submit()
|
||||
assert resp.location == 'http://example.net/backoffice/settings/users/fields/'
|
||||
resp = resp.follow()
|
||||
|
|
|
@ -28,7 +28,7 @@ from wcs.qommon.admin.menu import command_icon
|
|||
|
||||
from wcs import fields
|
||||
from wcs.formdef import FormDef
|
||||
from wcs.fields import get_field_types
|
||||
from wcs.fields import get_field_types, get_field_options
|
||||
import copy
|
||||
|
||||
|
||||
|
@ -248,10 +248,7 @@ class FieldsDirectory(Directory):
|
|||
|
||||
r += htmltext('<li class="biglistitem type-%s" id="itemId_%s" %s>' % (
|
||||
field.type, field.id, hidden))
|
||||
try:
|
||||
type_label = [x[1] for x in get_field_types() if x[0] == field.type][0]
|
||||
except IndexError:
|
||||
type_label = _('Unknown')
|
||||
type_label = field.get_type_label()
|
||||
if field.type in ('subtitle', 'title', 'comment'):
|
||||
label = misc.ellipsize(field.unhtmled_label, 60)
|
||||
if field.type in ('subtitle', 'title'):
|
||||
|
@ -311,7 +308,7 @@ class FieldsDirectory(Directory):
|
|||
required = True, size = 50)
|
||||
form.add(SingleSelectWidget, 'type', title = _('Type'),
|
||||
required=True,
|
||||
options = [(x, _(y)) for x,y in get_field_types() if x not in self.blacklisted_types])
|
||||
options=get_field_options(self.blacklisted_types))
|
||||
form.add_submit('submit', _('Add'))
|
||||
r += form.render()
|
||||
if self.support_import:
|
||||
|
@ -361,7 +358,7 @@ class FieldsDirectory(Directory):
|
|||
form.add(StringWidget, 'page_id')
|
||||
form.add(StringWidget, 'label', title = _('Label'), size = 50)
|
||||
form.add(SingleSelectWidget, 'type', title = _('Type'),
|
||||
options = [(x, _(y)) for x,y in get_field_types()])
|
||||
options=get_field_options(self.blacklisted_types))
|
||||
if FormDef.count():
|
||||
form.add(SingleSelectWidget, 'form', title = _('Or import fields from:'),
|
||||
options = [(x.id, x.name, x.id) for x in FormDef.select(
|
||||
|
|
|
@ -194,6 +194,9 @@ class Field(object):
|
|||
def init(cls):
|
||||
pass
|
||||
|
||||
def get_type_label(self):
|
||||
return _(self.description)
|
||||
|
||||
@property
|
||||
def include_in_listing(self):
|
||||
return 'listings' in (self.display_locations or [])
|
||||
|
@ -2598,3 +2601,15 @@ def get_field_class_by_type(type):
|
|||
def get_field_types():
|
||||
return field_types
|
||||
|
||||
|
||||
def get_field_options(blacklisted_types):
|
||||
widgets, non_widgets = [], []
|
||||
for klass in field_classes:
|
||||
if klass.key in blacklisted_types:
|
||||
continue
|
||||
if issubclass(klass, WidgetField):
|
||||
widgets.append((klass.key, _(klass.description), klass.key))
|
||||
else:
|
||||
non_widgets.append((klass.key, _(klass.description), klass.key))
|
||||
options = widgets + [('', '—', '')] + non_widgets
|
||||
return options
|
||||
|
|
Loading…
Reference in New Issue