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

add option for an upload limit #232

Merged
merged 1 commit into from
Aug 31, 2024

Conversation

goapunk
Copy link
Contributor

@goapunk goapunk commented Jul 18, 2024

  • add option for an upload limit
  • return the first form error as JsonResponse so the real error is shown to the user (instead of a generic upload failed)
  • add test_settings for pytest to make testing the file size easier
  • add tests for file extension and file size on upload

@goapunk goapunk force-pushed the jd-2024-07-upload-limit branch 6 times, most recently from 9f45862 to a0e6056 Compare July 18, 2024 14:47
Copy link
Owner

@hvlads hvlads Jul 28, 2024

Choose a reason for hiding this comment

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

Hi @goapunk. Thank you for your work. What is the purpose of test_settings, which repeats exactly settings.py ? maybe it's better to use override_settings?

@override_settings(CKEDITOR_5_MAX_FILE_SIZE=0.06)
def test_upload_file_too_big(admin_client, file_big):
    ...

Copy link
Contributor Author

@goapunk goapunk Aug 1, 2024

Choose a reason for hiding this comment

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

Hi @hvlads , I changed it to import all settings from settings.py to make it more readable now. Using @override_settings sadly doesn't work as the value is not read dynamically but set when initializing the FileMaxSizeValidator. I don't know how else to do it (except for changing the logic in the validator itself)

@goapunk goapunk force-pushed the jd-2024-07-upload-limit branch 3 times, most recently from c7f607a to 7092e0c Compare August 1, 2024 14:01
@goapunk goapunk requested a review from hvlads August 1, 2024 14:02
@goapunk goapunk force-pushed the jd-2024-07-upload-limit branch 3 times, most recently from 9538790 to 3e1c726 Compare August 5, 2024 10:20
- add a validator to validate the max file size (FileMaxSizeValidator)
- return the first form error in a JsonResponse so it is actually shown to the
  user instead of a generic error message.
- add separate test_settings for pytest (to allow testing with small
  file sizes)
- add tests for file extension and file size
@goapunk goapunk force-pushed the jd-2024-07-upload-limit branch from 3e1c726 to 6082a69 Compare August 5, 2024 10:25
@hvlads hvlads merged commit 9081d37 into hvlads:master Aug 31, 2024
1 check passed
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.

2 participants