misc: do not expose values for inhert fields (#82982) #803

Merged
fpeters merged 1 commits from wip/82982-no-data-fields into main 2023-11-01 08:13:22 +01:00
9 changed files with 25 additions and 7 deletions

View File

@ -5372,3 +5372,15 @@ def test_get_status_datetime(pub, freezer):
formdata.jump_status('new')
assert formdata.get_status_datetime(status=st_new) == formdata.evolution[0].time
assert formdata.get_status_datetime(status=st_new, latest=True) == formdata.evolution[-1].time
def test_page_field_var(pub, formdef):
formdef.fields = [fields.PageField(id='1', label='page', varname='page')]
formdef.store()
formdata = formdef.data_class()()
formdata.data = {}
formdata.store()
assert 'form_var_page' not in formdata.get_substitution_variables()
assert 'page' not in LazyFormData(formdata).var.inspect_keys()

View File

@ -1481,7 +1481,6 @@ class FormDefPage(Directory, TempfileDirectoryMixin):
def ellipsize_html(field):
return misc.ellipsize(field.unhtmled_label, 60)
nodata_types = ('page', 'title', 'subtitle', 'comment')
display_warning = False
for diffinfo in difflib.ndiff(current_fields_list, new_fields_list):
@ -1507,11 +1506,11 @@ class FormDefPage(Directory, TempfileDirectoryMixin):
# unchanged line
if current_field and new_field and current_field.key != new_field.key:
# different datatypes
if current_field.key in nodata_types:
if current_field.is_no_data_field:
# but current field doesn't hold data, not a problem
table += htmltext('<tr class="added-field"><td class="indicator">+</td>')
current_label = ''
elif new_field.key in nodata_types:
elif new_field.is_no_data_field:
# new field won't hold data, but old data will be removed
table += htmltext('<tr class="removed-field"><td class="indicator">-</td>')
new_label = ''

View File

@ -218,6 +218,7 @@ class Field:
store_structured_value = None
get_opendocument_node_value = None
condition = None
is_no_data_field = False
# flag a field for removal by AnonymiseWorkflowStatusItem
# possible values are final, intermediate, no.
@ -1081,10 +1082,10 @@ def get_field_options(blacklisted_types):
continue
if klass.key in disabled_fields:
continue
if issubclass(klass, WidgetField):
widgets.append((klass.key, klass.description, klass.key))
else:
if klass.is_no_data_field:
non_widgets.append((klass.key, klass.description, klass.key))
else:
widgets.append((klass.key, klass.description, klass.key))
options = widgets + [('', '', '')] + non_widgets
if 'computed' not in blacklisted_types:

View File

@ -39,6 +39,7 @@ class CommentField(Field):
key = 'comment'
description = _('Comment')
display_locations = []
is_no_data_field = True
def get_text(self):
import wcs.workflows

View File

@ -137,6 +137,7 @@ class PageCondition(Condition):
class PageField(Field):
key = 'page'
description = _('Page')
is_no_data_field = True
post_conditions = None

View File

@ -24,6 +24,7 @@ class SubtitleField(TitleField):
key = 'subtitle'
description = _('Subtitle')
html_tag = 'h4'
is_no_data_field = True
register_field_class(SubtitleField)

View File

@ -30,6 +30,7 @@ class TitleField(Field):
description = _('Title')
html_tag = 'h3'
display_locations = ['validation', 'summary']
is_no_data_field = True
def add_to_form(self, form, value=None):
import wcs.workflows

View File

@ -1353,7 +1353,7 @@ def do_views(formdef, conn, cur, rebuild_global_views=True):
column_names = {}
for field in formdef.get_all_fields():
field_key = get_field_id(field)
if field.key in ('page', 'title', 'subtitle', 'comment'):
if field.is_no_data_field:
continue
if field.varname:
# the variable should be fine as is but we pass it through

View File

@ -1054,6 +1054,8 @@ class LazyFormDataVar:
return self._varnames
self._varnames = {}
for field in self._fields:
if field.is_no_data_field:
continue
if not field.varname or not CompatibilityNamesDict.valid_key_regex.match(field.varname):
continue
if field.varname in self._varnames: