matthewwithanm / pilkit

Utilities and processors built for, and on top of PIL
BSD 3-Clause "New" or "Revised" License
196 stars 54 forks source link

Problem when specifying a label argument for a ProcessedImageField #16

Closed alsoicode closed 9 years ago

alsoicode commented 9 years ago

I'm getting an interesting exception when using a ProcessedImageField from django-imagekit in processors/base.py line 15 using Python 3.4 and Django 1.7.4 and specifying a label argument on my model:

AttributeError: 'str' object has no attribute 'process'

self     ['P', 'r', 'o', 'f', 'i', 'l', 'e', ' ', 'I', 'm', 'a', 'g', 'e']
proc    'P'
img    <PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=80x80 at 0x7F6A6445A550>

It looks like the ProcessedImageField might be making some incorrect assumptions about what args are passed to it. If I define my model as:

class Profile(models.Model):
    image = ProcessedImageField('Profile Image', format='JPEG', options={'quality': 60})

the AttributeError is thrown. If I remove the label argument for the field, it works as expected.

matthewwithanm commented 9 years ago

Hmm, I'm pretty sure this isn't a pilkit thing; looks like just IK is involved.

You're seeing this error because the first argument to ProcessedImageField is an iterable of processors, but you're providing a string. (This is the same problem you're seeing in matthewwithanm/django-imagekit#308.)

What does that string ("Profile Image") represent? Is there some documentation that shows the constructor accepting that?

alsoicode commented 9 years ago

Perhaps this is a bit of legacy code in Djago that still works, as I can't find it in the current docs online, but you can provide a string as the first argument of a field, except in the case of a ForeignKey or ManyToMany and it will be used as the label attribute for the field.

I've just moved those labels to the form class for the model to work around it, but that's something I've done for years with model fields where I don't need a separate ModelForm class.

matthewwithanm commented 9 years ago

Ah okay. Well I'm going to close this since it's not really a pilkit issue and it's the same as matthewwithanm/django-imagekit#308. We should be able to add support for that but we'll have to be careful not to break anything for people passing processors in as an unnamed, first position arg (i.e by checking if it's a string).