def delete_file(profile, img): form = forms.DeleteImageForm() if form.is_submitted(): queueit('delete', img, taskid=img.name + img.extn) flash("%s is deleted" % img.title) else: return render_template('delete.html', form=form, file=img, profile=profile) return redirect(url_for('profile_view', profile=profile.name))
def get_resized_image(img, size, is_thumbnail=False): """ Check if `img` is available with `size` if not make a one. Return the name of it. """ img_name = img.name size_t = parse_size(size) if (size_t and size_t[0] != img.width and size_t[1] != img.height) or ('thumb_extn' in ALLOWED_MIMETYPES[img.mimetype] and ALLOWED_MIMETYPES[img.mimetype]['thumb_extn'] != img.extn): w_or_h = or_(Thumbnail.width == size_t[0], Thumbnail.height == size_t[1]) scaled = Thumbnail.query.filter(w_or_h, Thumbnail.stored_file == img).first() if scaled: img_name = scaled.name else: size = get_fitting_size((img.width, img.height), size_t) resized_filename = get_resized_filename(img, size) job = queueit('resize_and_save', img, size, is_thumbnail=is_thumbnail, taskid=resized_filename) return job return img_name
def save(fp, profile, title=None): """ Attaches the image to the profile and uploads it to S3. """ id_ = newid() title = title or secure_filename(fp.filename) content_type = get_file_type(fp) name, extn = os.path.splitext(fp.filename) extn = guess_extension(content_type, extn) img_name = "%s%s" % (id_, extn) local_path = path_for(img_name) with open(local_path, 'w') as img: img.write(fp.read()) stored_file = save_img_in_db(name=id_, title=title, local_path=local_path, profile=profile, mimetype=content_type, orig_extn=extn) job = queueit('save_on_s3', img_name, content_type=content_type, taskid=img_name) return title, job, stored_file