django-imagekit
django-imagekit copied to clipboard
Add SafeImageSpecField
Add SafeImageSpecField that will not raise exception if source file is absent.
Can you show me an example of code that's raising an exception?
Use objects inherit for that:
class SafeProcessedImageField(ProcessedImageField):
def clean(self, data, initial=None):
data = super(ProcessedImageField, self).clean(data, initial)
if data and data != initial:
spec = self.get_spec(source=data)
try:
data = generate(spec)
except (IndexError, IOError, ValueError, OverflowError) as e:
pass
return data
And use it your forms:
class PhotoForm(forms.Form):
photo = SafeProcessedImageField(spec_id='model:photo')