Re: [Django] #16396: Validation Problem Reading Files When Using Custom Storage Module

2011-07-06 Thread Django
#16396: Validation Problem Reading Files When Using Custom Storage Module
-+-
   Reporter: |  Owner:  nobody
  dadealeus@…| Status:  closed
   Type:  Bug|  Component:  Documentation
  Milestone: |   Severity:  Normal
Version:  1.3|   Keywords:  validation storage
 Resolution:  invalid|  custom
   Triage Stage: |  Has patch:  0
  Unreviewed |Needs tests:  0
Needs documentation:  0  |  Easy pickings:  0
Patch needs improvement:  0  |
  UI/UX:  0  |
-+-
Changes (by aaugustin):

 * status:  new => closed
 * needs_better_patch:   => 0
 * resolution:   => invalid
 * needs_tests:   => 0
 * needs_docs:   => 0


Comment:

 Given the following sentence, I'd say the bug is in your custom storage
 module:
 > Using the native django storage, the exact same code functions without
 any issues.

 

 It's up to the storage model to reset the file, not the form. For
 instance, `django.core.files.base.File` does it in `open` and `__iter__`
 (via `chunks`).

 The docs say it's possible to override any of the storage methods
 explained in File storage API, but don't say how. They assume you will
 read the source  and understand the requirements. If you don't use the
 `File` class or a subclass, you should make sure that your code has a
 similar behavior.

 Given that we hardly have the most basic documentation here, I don't think
 it makes sense to describe this specific pitfall.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Django] #16396: Validation Problem Reading Files When Using Custom Storage Module

2011-07-03 Thread Django
#16396: Validation Problem Reading Files When Using Custom Storage Module
---+---
 Reporter:  dadealeus@…|  Owner:  nobody
 Type:  Bug| Status:  new
Milestone: |  Component:  Documentation
  Version:  1.3|   Severity:  Normal
 Keywords:  validation storage custom  |   Triage Stage:  Unreviewed
Has patch:  0  |  Easy pickings:  0
UI/UX:  0  |
---+---
 Using a custom storage module I wrote using the Rackspace CloudFiles API,
 if I perform any sort of reads on a file object during custom validation
 of uploaded files, I need to seek back the beginning of the file before I
 return it as cleaned_data.

 Example form class:

 {{{
 class UploadImageForm(forms.Form):
 """ Form to handle design uploads """
 design = forms.ImageField(error_messages={'required' : "Please
 select an image to upload."})

 def clean_design(self):

 from generic.media import utils

 # Verify uploaded image is an image
 data = self.cleaned_data['design']

 # Open the image so we can autocrop before checking dimensions
 image = PIL.open(StringIO(data.read()))

 # Autocrop the image and then check the dimensions
 image = utils.autoCrop(image)

 # Minimum image size
 min_image_size = 90

 # Verify the image size
 width, height = image.size
 width = float(width)
 height = float(height)
 ratio = height / width

 # Perform various validation checks... Example:
 if (ratio > 16) or (ratio < 0.0625):
 raise forms.ValidationError("The uploaded image's aspect
 ratio is too extreme. Please use an image that looks more square.")

 return data
 }}}

 Upon trying to save an image with the cleaned data (while using my custom
 storage module) via a custom view, the file object has no data associated
 with it unless I seek back to 0 before returning the cleaned data.

 Please note that this only occurs when using my custom storage module and
 when performing custom validation on the uplodaded data. Using the native
 django storage, the exact same code functions without any issues.

 I would like to see a note added to the custom storage documentation that
 specifies something like:

 "If performing custom validation on a file object while using a custom
 storage module, be sure to seek back to zero before passing back the
 cleaned data as the file object is returned in its current state.

 Example:

 {{{
 class UploadImageForm(forms.Form):
 """ Form to handle image uploads """
 image = forms.ImageField(error_messages={'required' : "Please
 select an image to upload."})

 def clean_image(self):

 data = self.cleaned_data['image']
 stringIO = data.read()

 # Perform some custom validation

 # Reset the file object before returning it as cleaned data
 data.seek(0)
 return data
 }}}


 "

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.