def get_save_FIELD_file self def _get_FIELD_file instance filename raw

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
def get_save_FIELD_file(self):
def _get_FIELD_file(instance, filename, raw_contents, save=True):
img_data = StringIO()
resized_img = resize_image(
Image.open(StringIO(raw_contents)),
width=self.width,height=self.height)
print 'format:',resized_img.format
resized_img.save(img_data,format=resized_img.format)
raw_contents = img_data.getvalue()
instance._save_FIELD_file(self, filename, raw_contents, save)
return _get_FIELD_file
def contribute_to_class(self, cls, name):
super(SmartImageField, self).contribute_to_class(cls, name)
# overwrite parent binding to 'save_%s_file'
setattr(cls, 'save_%s_file' % self.name, self.get_save_FIELD_file())