Set multipart enctype on the sample header form so file uploads persist#2960
Open
ramonski wants to merge 1 commit into
Open
Set multipart enctype on the sample header form so file uploads persist#2960ramonski wants to merge 1 commit into
ramonski wants to merge 1 commit into
Conversation
The senaite-sampleheader-form declares method='post' without enctype='multipart/form-data', so any AT FileField rendered inline in the header table posts as a filename string instead of a real FileUpload. The widget's process_form then sees a string, finds no .filename attribute, and silently treats the field as empty - the file disappears on save even though the rest of the form submit succeeds. Setting the enctype matches what every other Plone form with file inputs does (base_edit, AR Add, attachments) and lets custom widgets like ExtFileField extensions on AnalysisRequest roundtrip through the sample header form correctly.
9820f84 to
6192a3e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of the issue/feature this PR addresses
Linked issue: -
The
senaite-sampleheader-formtemplate declaresmethod="post"but noenctype="multipart/form-data". As a result the browser submits the value of any<input type="file">rendered inside that form as a plain filename string instead of a realFileUploadobject. The widget'sprocess_formthen receives astr,getattr(value, "filename", "")is"", the widget treats the upload as no-change (correctly, given the input), and the file is silently dropped on save.This is straightforward to hit when an
ExtFileField(or any AT widget that expects to read its upload fromrequest.form) is added toAnalysisRequestvia a schema extender and made visible inheader_table. The form submit otherwise succeeds, so there is no error to point at — the file just never persists.Current behavior before PR
File uploads from a
FileField/ExtFileFieldrendered in the sample header table are silently dropped on save:request.form["<field>_file"]is the string\"my.pdf\", the widget short-circuits, and the field remains empty.Desired behavior after PR is merged
Files posted from the sample header form arrive as
FileUploadinstances, the widget'sprocess_formreads the upload, and the field persists — matching the behaviour of every other Plone form with file inputs (base_edit, AR Add, attachments).--
I confirm I have tested this PR thoroughly and coded it according to PEP8
and Plone's Python styleguide standards.