Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for fieldname-prefixed values on sample header submit #2364

Merged
merged 2 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
2.5.0 (unreleased)
------------------

- #2364 Support for fieldname-prefixed values on sample header submit
- #2363 Auto-hide non-multivalued reference widget input on value selection
- #2359 Improve sample create performance
- #2361 Fix KeyError if registry key not found
Expand Down
13 changes: 8 additions & 5 deletions src/senaite/core/browser/viewlets/sampleheader.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,20 @@ def handle_form_submit(self, request=None):
form = request.form

for name, field in self.fields.items():
# get the raw value from the form. This shouldn't be necessary,
# but there are still some widgets out there with a name that
# follows the format <fieldname>_uid. Otherwise, we could simply
# pass the form object to the widget's process_form function.
# get the raw value from the form
value = self.get_field_value(field, form)
if value is _fieldname_not_in_form:
continue

# some legacy widgets need values with <fieldname>_ as prefix
prefix = "{}_".format(name)
extra = filter(lambda key: key.startswith(prefix), form.keys())
form_values = dict((key, form[key]) for key in extra)
form_values[name] = value

# process the value as the widget would usually do
process_value = field.widget.process_form
value, msgs = process_value(self.context, field, {name: value})
value, msgs = process_value(self.context, field, form_values)

# Keep track of field-values
field_values.update({name: value})
Expand Down