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
Add MultipleFileField to handle and clean multiple files #465
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #466 which exposes another underlying issue related to the validation of the files uploaded via the FilesAnnotationForm
(and allows to create a scenario to test this PR).
While testing the two PRs together, it should be noted that this PR requires Django 3.2.19 as the API for auto-setting multiple: true
when allow_multiple_selected
is set to True was introduced in django/django@eed53d0. In other terms, with this PR and Django 3.2.18, the multiple selection is disabled. Django should be set to 3.2.19 as the minimum version via setup.py
Excluding to allow testing of #466 ahead of this... EDIT: remove flag |
Testing on merge-ci:
|
omeroweb/webclient/forms.py
Outdated
@@ -62,6 +62,28 @@ | |||
) % help_button | |||
|
|||
|
|||
################################################################# | |||
# Custom widget and validation for multiple file uploads |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having looked at how the code is organized, all custom widget/fields are declared omeroweb.webclient.custom_forms
and imported here to construct the webclient forms.
omeroweb/webclient/forms.py
Outdated
|
||
|
||
class MultipleFileInput(forms.ClearableFileInput): | ||
allow_multiple_selected = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth adding a comment and/or a reference to the documentation explaining why we are subclassing these Django classes.
Functional test looks good 👍 If there's one empty file included in a multi file upload then none of the files get uploaded/attached, not even the non-empty ones. Is that expected? |
@dominikl that's the expectation as per the new field class. If any of the files fails validation, then the entire multi-file upload is cancelled. The other place that uses a @will-moore is there a way to propagate the error message to the user in the files annotation UI? |
@dominikl - yes the whole form is considered invalid if any file is invalid. |
👍 I don't think either that it has to go into this PR, better get it out as soon as possible. |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last commit follows the new recommendation from Django documentation with a new custom class and restores compatibility with Django 3.2.19.
The last commit will need to be retested functionally but from a code review perspective, no objection to moving forward with the current suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good to me
Running https://merge-ci.openmicroscopy.org/jenkins/job/OMERO-python-superbuild-push/1446/ to include latest changes... |
Tested on merge-ci, user-3. From jenkins, this PR is included on https://merge-ci.openmicroscopy.org/jenkins/job/OMERO-python-superbuild-push/1447/console
The test:
The tests went as expected, the file upload was rejected in all cases where the empty file was selected, either with non-empty files or alone. LGTM |
Fixes #464
This adds the update suggested at the last link below to conform to the security release below:
#410
https://www.djangoproject.com/weblog/2023/may/03/security-releases/
django/django@eed53d0
To test: