Opened 6 years ago

Closed 11 months ago

#10935 closed Cleanup/optimization (fixed)

forms.ImageField.clean should annotate the object returned by FileField.clean

Reported by: jdunck Owned by: petraszd
Component: Forms Version: master
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 Changed 6 years ago by jdunck

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 6 years ago by jcd

  • Triage Stage changed from Unreviewed to Design decision needed

comment:3 Changed 5 years ago by jacob

  • milestone changed from 1.2 to 1.3

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

comment:4 Changed 5 years ago by ubernostrum

  • milestone 1.3 deleted

1.3 is feature-frozen now.

comment:5 Changed 4 years ago by lukeplant

  • Severity set to Normal
  • Type set to Cleanup/optimization

comment:6 Changed 3 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:7 Changed 3 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:8 Changed 2 years ago by jacob

  • Triage Stage changed from Design decision needed to Accepted

comment:9 Changed 11 months ago by petraszd

  • Owner changed from nobody to petraszd
  • Status changed from new to assigned

comment:10 Changed 11 months ago by petraszd

  • Has patch set

comment:11 Changed 11 months ago by petraszd

  • Needs documentation unset

comment:12 Changed 11 months ago by slurms

  • Patch needs improvement set

comment:13 Changed 11 months 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.

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

comment:14 Changed 11 months ago by timo

  • Resolution set to fixed
  • Status changed from assigned to 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.

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