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 Jeremy Dunck, 16 years ago

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.

comment:2 by Cliff Dyer, 15 years ago

Triage Stage: UnreviewedDesign decision needed

comment:3 by Jacob, 15 years ago

milestone: 1.21.3

I'm calling this a feature, and kicking it out of 1.2.

comment:4 by James Bennett, 14 years ago

milestone: 1.3

1.3 is feature-frozen now.

comment:5 by Luke Plant, 14 years ago

Severity: Normal
Type: Cleanup/optimization

comment:6 by Aymeric Augustin, 13 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:7 by Aymeric Augustin, 13 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:8 by Jacob, 12 years ago

Triage Stage: Design decision neededAccepted

comment:9 by petraszd, 10 years ago

Owner: changed from nobody to petraszd
Status: newassigned

comment:10 by petraszd, 10 years ago

Has patch: set

comment:11 by petraszd, 10 years ago

Needs documentation: unset

comment:12 by Nick Sandford, 10 years ago

Patch needs improvement: set

comment:13 by petraszd, 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.

https://github.com/django/django/pull/2972

comment:14 by Tim Graham, 10 years ago

Resolution: fixed
Status: assignedclosed

In 8b7347220f3d86b46f5f87270c6cdcb9960895fd:

Fixed #10935 -- Annotated ImageField file with image and content_type attributes.

Thanks Jeremy Dunck for the suggestion and Nick Sanford for review.

Note: See TracTickets for help on using tickets.
Back to Top