misc: add option to disable some fields (#56118)
gitea-wip/wcs/pipeline/head Build started...
Details
gitea-wip/wcs/pipeline/head Build started...
Details
This commit is contained in:
parent
f85302d28b
commit
de23297457
|
@ -1,3 +1,4 @@
|
|||
import os
|
||||
import re
|
||||
|
||||
import pytest
|
||||
|
@ -642,3 +643,103 @@ def test_file_convert_from_anything():
|
|||
)
|
||||
assert value.base_filename == 'test.txt'
|
||||
assert value.get_file_pointer().read() == b'hello'
|
||||
|
||||
|
||||
def test_new_field_type_options(pub):
|
||||
pub.load_site_options()
|
||||
if not pub.site_options.has_section('options'):
|
||||
pub.site_options.add_section('options')
|
||||
pub.site_options.set('options', 'disabled-fields', '')
|
||||
with open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w') as fd:
|
||||
pub.site_options.write(fd)
|
||||
|
||||
assert fields.get_field_options(blacklisted_types=[]) == [
|
||||
('string', 'Text (line)', 'string'),
|
||||
('text', 'Long Text', 'text'),
|
||||
('email', 'Email', 'email'),
|
||||
('bool', 'Check Box (single choice)', 'bool'),
|
||||
('file', 'File Upload', 'file'),
|
||||
('date', 'Date', 'date'),
|
||||
('item', 'List', 'item'),
|
||||
('items', 'Multiple choice list', 'items'),
|
||||
('table', 'Table', 'table'),
|
||||
('table-select', 'Table of Lists', 'table-select'),
|
||||
('tablerows', 'Table with rows', 'tablerows'),
|
||||
('map', 'Map', 'map'),
|
||||
('ranked-items', 'Ranked Items', 'ranked-items'),
|
||||
('password', 'Password', 'password'),
|
||||
('', '—', ''),
|
||||
('title', 'Title', 'title'),
|
||||
('subtitle', 'Subtitle', 'subtitle'),
|
||||
('comment', 'Comment', 'comment'),
|
||||
('page', 'Page', 'page'),
|
||||
('', '—', ''),
|
||||
('computed', 'Computed Data', 'computed'),
|
||||
]
|
||||
assert fields.get_field_options(blacklisted_types=['password', 'page']) == [
|
||||
('string', 'Text (line)', 'string'),
|
||||
('text', 'Long Text', 'text'),
|
||||
('email', 'Email', 'email'),
|
||||
('bool', 'Check Box (single choice)', 'bool'),
|
||||
('file', 'File Upload', 'file'),
|
||||
('date', 'Date', 'date'),
|
||||
('item', 'List', 'item'),
|
||||
('items', 'Multiple choice list', 'items'),
|
||||
('table', 'Table', 'table'),
|
||||
('table-select', 'Table of Lists', 'table-select'),
|
||||
('tablerows', 'Table with rows', 'tablerows'),
|
||||
('map', 'Map', 'map'),
|
||||
('ranked-items', 'Ranked Items', 'ranked-items'),
|
||||
('', '—', ''),
|
||||
('title', 'Title', 'title'),
|
||||
('subtitle', 'Subtitle', 'subtitle'),
|
||||
('comment', 'Comment', 'comment'),
|
||||
('', '—', ''),
|
||||
('computed', 'Computed Data', 'computed'),
|
||||
]
|
||||
|
||||
pub.site_options.set('options', 'disabled-fields', 'table, password, ')
|
||||
with open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w') as fd:
|
||||
pub.site_options.write(fd)
|
||||
|
||||
assert fields.get_field_options(blacklisted_types=[]) == [
|
||||
('string', 'Text (line)', 'string'),
|
||||
('text', 'Long Text', 'text'),
|
||||
('email', 'Email', 'email'),
|
||||
('bool', 'Check Box (single choice)', 'bool'),
|
||||
('file', 'File Upload', 'file'),
|
||||
('date', 'Date', 'date'),
|
||||
('item', 'List', 'item'),
|
||||
('items', 'Multiple choice list', 'items'),
|
||||
('table-select', 'Table of Lists', 'table-select'),
|
||||
('tablerows', 'Table with rows', 'tablerows'),
|
||||
('map', 'Map', 'map'),
|
||||
('ranked-items', 'Ranked Items', 'ranked-items'),
|
||||
('', '—', ''),
|
||||
('title', 'Title', 'title'),
|
||||
('subtitle', 'Subtitle', 'subtitle'),
|
||||
('comment', 'Comment', 'comment'),
|
||||
('page', 'Page', 'page'),
|
||||
('', '—', ''),
|
||||
('computed', 'Computed Data', 'computed'),
|
||||
]
|
||||
assert fields.get_field_options(blacklisted_types=['password', 'page']) == [
|
||||
('string', 'Text (line)', 'string'),
|
||||
('text', 'Long Text', 'text'),
|
||||
('email', 'Email', 'email'),
|
||||
('bool', 'Check Box (single choice)', 'bool'),
|
||||
('file', 'File Upload', 'file'),
|
||||
('date', 'Date', 'date'),
|
||||
('item', 'List', 'item'),
|
||||
('items', 'Multiple choice list', 'items'),
|
||||
('table-select', 'Table of Lists', 'table-select'),
|
||||
('tablerows', 'Table with rows', 'tablerows'),
|
||||
('map', 'Map', 'map'),
|
||||
('ranked-items', 'Ranked Items', 'ranked-items'),
|
||||
('', '—', ''),
|
||||
('title', 'Title', 'title'),
|
||||
('subtitle', 'Subtitle', 'subtitle'),
|
||||
('comment', 'Comment', 'comment'),
|
||||
('', '—', ''),
|
||||
('computed', 'Computed Data', 'computed'),
|
||||
]
|
||||
|
|
|
@ -3499,11 +3499,15 @@ def get_field_types():
|
|||
|
||||
def get_field_options(blacklisted_types):
|
||||
widgets, non_widgets = [], []
|
||||
disabled_fields = (get_publisher().get_site_option('disabled-fields') or '').split(',')
|
||||
disabled_fields = [f.strip() for f in disabled_fields if f.strip()]
|
||||
for klass in field_classes:
|
||||
if klass is ComputedField:
|
||||
continue
|
||||
if klass.key in blacklisted_types:
|
||||
continue
|
||||
if klass.key in disabled_fields:
|
||||
continue
|
||||
if issubclass(klass, WidgetField):
|
||||
widgets.append((klass.key, klass.description, klass.key))
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue