def bookmarklet(): opt = { 'is_login': False, 'is_active': False, 'done': False, } if g.user: opt['is_login'] = True if g.user.active: opt['is_active'] = True if request.method == 'GET': opt['address'] = request.args.get('url', '') media_tuple = MediaController.inspect_url(form_data=opt) opt['result'] = MediaController.route_parser(media_tuple=media_tuple) elif request.method == 'POST': inspected_data = MediaController.inspect_url(request.form) created_media, created_flag = MediaController.get_or_create(inspected_data) playlist = UserController.get_archived_playlist() success = PlaylistController.add_media(playlist=playlist, media=created_media) if success: opt['done'] = True else: opt['fail'] = True return render_template("media/bookmarklet.html", **opt)
def archive(): if request.method == 'GET': opt = { 'bookmarklet_address': url_for('media.bookmarklet', _external=True), } return render_template("media/archive.html", **opt) else: inspected_data = MediaController.inspect_url(request.form) created_media, created_flag = MediaController.get_or_create(inspected_data) playlist = UserController.get_archived_playlist() success = PlaylistController.add_media(playlist=playlist, media=created_media) if not success: flash(u'failed to archive') return redirect(url_for('user.archived'))