Opened 16 years ago
Closed 10 years ago
#10935 closed Cleanup/optimization (fixed)
forms.ImageField.clean should annotate the object returned by FileField.clean
Reported by: | Jeremy Dunck | Owned by: | petraszd |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
ImageField.clean does some validation that the given file is, in fact, an image, but then just returns whatever the FileField gave it-- generally an UploadedFile.
I have a later Form.clean_* method which needs to do further work with the image, and so uses Image.open again.
I think it'd be good to annotate the UploadedFile with an image attribute to save the work of parsing the image yet again.
f.image = trial_image
Agree?
Change History (14)
comment:1 by , 16 years ago
comment:2 by , 15 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|
comment:3 by , 15 years ago
milestone: | 1.2 → 1.3 |
---|
I'm calling this a feature, and kicking it out of 1.2.
comment:5 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Cleanup/optimization |
comment:8 by , 12 years ago
Triage Stage: | Design decision needed → Accepted |
---|
comment:9 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:10 by , 10 years ago
Has patch: | set |
---|
Pull request: https://github.com/django/django/pull/2972
comment:11 by , 10 years ago
Needs documentation: | unset |
---|
comment:12 by , 10 years ago
Patch needs improvement: | set |
---|
comment:13 by , 10 years ago
Patch needs improvement: | unset |
---|
Updated pull request according to comments in github. And now it also included setting content_type by using information Pillow provides.
comment:14 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
In 8b7347220f3d86b46f5f87270c6cdcb9960895fd:
Fixed #10935 -- Annotated ImageField file with image and content_type attributes.
Thanks Jeremy Dunck for the suggestion and Nick Sanford for review.
Also, as long as it's opening the image, I think it should correct content_type based on the actual format of the image. Most OS's will mis-report the content type of the upload based on its extension, so that a JPEG named something.gif is reported as image/gif.