def deserialize(self): """ override ImageFieldRenderer deserialize """ if self._path: return self._path data = FieldRenderer.deserialize(self) if isinstance(data, cgi.FieldStorage): info = ip.process_image(data.file) self._path = info['uri'] return self._path checkbox_name = '%s--remove' % self.name if not data and not self.params.has_key(checkbox_name): data = getattr(self.field.model, self.field.name) return self._path
def _import(self, abspath): # check same image has not already been imported hash = img_md5(abspath) photo = DBSession.query(Photo).filter_by(md5sum=hash) if photo.count() > 0: log.info("Same md5sum already exists in database") return photo.first() # process and import photos to public/data/photos dir info = ip.process_image(abspath, md5sum=hash) os.unlink(abspath) # import image in db photo = Photo() photo.uri = info["uri"] photo.md5sum = hash photo.time = info["date"] DBSession.add(photo) DBSession.flush() return info