Opened 14 years ago

Closed 9 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


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 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


Change History (14)

comment:1 Changed 14 years ago by Jeremy Dunck

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 Changed 14 years ago by Cliff Dyer

Triage Stage: UnreviewedDesign decision needed

comment:3 Changed 14 years ago by Jacob

milestone: 1.21.3

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

comment:4 Changed 13 years ago by James Bennett

milestone: 1.3

1.3 is feature-frozen now.

comment:5 Changed 12 years ago by Luke Plant

Severity: Normal
Type: Cleanup/optimization

comment:6 Changed 12 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:7 Changed 12 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:8 Changed 11 years ago by Jacob

Triage Stage: Design decision neededAccepted

comment:9 Changed 9 years ago by petraszd

Owner: changed from nobody to petraszd
Status: newassigned

comment:10 Changed 9 years ago by petraszd

Has patch: set

comment:11 Changed 9 years ago by petraszd

Needs documentation: unset

comment:12 Changed 9 years ago by Nick Sandford

Patch needs improvement: set

comment:13 Changed 9 years ago by petraszd

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 Changed 9 years ago by Tim Graham

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