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

[#1795] Add backend support for multiple file upload #855

Merged
merged 6 commits into from
Nov 24, 2023

Conversation

pi-sigma
Copy link
Contributor

Taiga: #1795

Front-end: PR #833

@pi-sigma pi-sigma force-pushed the feature/1795-doc-upload-backend branch 2 times, most recently from 2bc6822 to 6da0043 Compare November 22, 2023 15:11
@codecov-commenter
Copy link

codecov-commenter commented Nov 22, 2023

Codecov Report

Attention: 41 lines in your changes are missing coverage. Please review.

Comparison is base (116e0ab) 92.93% compared to head (e35db34) 92.79%.
Report is 2 commits behind head on develop.

Files Patch % Lines
src/open_inwoner/cms/cases/tests/test_htmx.py 6.97% 40 Missing ⚠️
src/open_inwoner/utils/forms.py 91.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #855      +/-   ##
===========================================
- Coverage    92.93%   92.79%   -0.15%     
===========================================
  Files          775      776       +1     
  Lines        26636    26713      +77     
===========================================
+ Hits         24754    24787      +33     
- Misses        1882     1926      +44     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pi-sigma pi-sigma force-pushed the feature/1795-doc-upload-backend branch from 6da0043 to 733a65b Compare November 22, 2023 15:54
Copy link
Contributor

@svenvandescheur svenvandescheur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would recommend using get_by_label, other than that, based on a quick look this seems fine to me (didn’t do ann actual test yet though).

@@ -432,7 +432,7 @@ def test_cases(self, m):
upload_form = page.locator("#document-upload")
expect(upload_form).to_be_visible()

file_input = upload_form.get_by_text(_("Sleep of selecteer bestand"))
file_input = page.locator("[name='file']")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should prefer the get_by_label where possible (or any other selector that testes a11y).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the id and for attributes for the input and label elements to make the test work with get_by_label. Let me know if this is not desirable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did do a small change, instead of using a hardcoded id I used the "auto_id" for both the input and the label.

src/open_inwoner/cms/cases/views/status.py Show resolved Hide resolved
@@ -3,7 +3,7 @@
<div class="form__control file-input">
{% render_card direction="vertical" %}
{% icon icon="upload" icon_position="before" outlined=True %}
<input class="file-input__input" id="{{ field.auto_id }}" name="file" type="file"{% if field.field.required %} required{% endif %}>
<input class="file-input__input" id="{{ field.auto_id }}" name="file" type="file"{% if field.field.required %} required{% endif %} multiple>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be dynamic based on the field type, and shouldn't we (dynamically) change the labels into plurals accordingly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

multiple should be set dynamically and has been fixed. I'm not sure about the labels. There's no change in the backend if the client drops a file or two into the widget, so I'm not sure what could decide if the label should be singular or plural. Passing that info front to back seems overkill. I tend towards leaving it as is, or perhaps use an "optional plural" form like "Selecteer bestand(en)"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the label simply based on multiple. I don't think we need to have plural forms based on the length of the selection.

@pi-sigma pi-sigma force-pushed the feature/1795-doc-upload-backend branch 5 times, most recently from 02d41ae to 4678342 Compare November 23, 2023 14:06
@pi-sigma pi-sigma marked this pull request as ready for review November 23, 2023 14:17
@pi-sigma pi-sigma force-pushed the feature/1795-doc-upload-backend branch from 4678342 to 998b97e Compare November 23, 2023 14:32
Copy link
Contributor

@jiromaykin jiromaykin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work - the Success notification does have the annoying habit of becoming sticky and it should get into Focus after a successful upload, but that's not part of this task.

@svenvandescheur svenvandescheur force-pushed the feature/1795-doc-upload-backend branch from d0bf625 to d11eb91 Compare November 23, 2023 16:23
created_relationship = connect_case_with_document(
self.case.url, created_document.get("url")
)
except AttributeError:
Copy link
Contributor

@svenvandescheur svenvandescheur Nov 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pi-sigma I've added the AttributeError handling here because created_document could be None, however I think we might want to separate the error handling for the both objects and only create the relationship if the document is actually created.

This might require some small refactoring here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@svenvandescheur I don't think we need to expose this to the user; they only care about whether the upload worked or not.

Relatedly, I tested the code again and it now fails with getattr for me too, as it should. So I think we're good to go.

@pi-sigma pi-sigma force-pushed the feature/1795-doc-upload-backend branch from d11eb91 to e35db34 Compare November 24, 2023 09:40
@svenvandescheur svenvandescheur merged commit ae363ca into develop Nov 24, 2023
14 checks passed
@svenvandescheur svenvandescheur deleted the feature/1795-doc-upload-backend branch November 24, 2023 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants