def edit_application(application, data_dict, image, keep_images): if 'image' in data_dict: del data_dict['image'] data, errors = validate(data_dict, application_schema()) if errors: raise ValidationError(errors, error_summary(errors)) application.title = data.get('title') application.url = data.get('url') application.description = data.get('description') application.featured = data.get('featured') application.submitter = data.get('submitter') application.developer = data.get('developer') application.developer_url = data.get('developer_url') application.license = data.get('license') application.code_url = data.get('code_url') application.api_url = data.get('api_url') tags = data.get('tags', '').split(' ') application.update_tags(tags) for _image in application.images: if _image.id not in keep_images: _image.delete() if image is not None and hasattr(image, 'file'): image = ApplicationImage(name=image.filename, data=image.file.read(), application=application) image.save() application.save() return application
def read_image(self, id, x=None, y=None): etag_cache(sha1(str(id)+str(x)+str(y)).hexdigest()) image = ApplicationImage.by_id(id) handle = Image.open(StringIO(image.data)) if not image: abort(404) response.content_type = 'image/png' outfh = StringIO() try: if x is not None and y is not None: size = (int(x), int(y)) handle = ImageOps.fit(handle, size, Image.ANTIALIAS, 0.01, (0.0, 0.0)) except ValueError, e: pass