def playlist_extend(channel, playlist): form = PlaylistImportForm() form.channel = channel html = render_template('playlist-extend.html', form=form, channel=channel, playlist=playlist) if request.is_xhr: if form.validate_on_submit(): playlist_url = escape(form.playlist_url.data) initial_count = len(playlist.videos) try: process_playlist(playlist_url=playlist_url, playlist=playlist) except: return jsonify({'message_type': "server-error", 'message': 'Oops, something went wrong, please try later'}) additions = (len(playlist.videos) - initial_count) if additions: db.session.commit() cache.delete('data/featured-channels') flash(u"Added '%d' videos" % (len(playlist.videos) - initial_count), 'success') return jsonify({'message_type': "success", 'action': 'redirect', 'url': playlist.url_for()}) return jsonify({'message_type': "success", 'action': 'noop', 'message': 'Already upto date'}) if form.errors: html = render_template('playlist-extend.html', form=form, channel=channel, playlist=playlist) return jsonify({'message_type': "error", 'action': 'append', 'html': html}) return jsonify({'action': 'modal-window', 'message_type': 'success', 'html': html}) return html
def playlist_extend(channel, playlist): form = PlaylistImportForm() form.channel = channel html = render_template('playlist-extend.html.jinja2', form=form, channel=channel, playlist=playlist) if request.is_xhr: if form.validate_on_submit(): playlist_url = escape(form.playlist_url.data) initial_count = len(playlist.videos) try: process_playlist(playlist_url=playlist_url, playlist=playlist) except: return jsonify({ 'message_type': "server-error", 'message': 'Oops, something went wrong, please try later' }) additions = (len(playlist.videos) - initial_count) if additions: db.session.commit() cache.delete('data/featured-channels') flash( u"Added '%d' videos" % (len(playlist.videos) - initial_count), 'success') return jsonify({ 'message_type': "success", 'action': 'redirect', 'url': playlist.url_for() }) return jsonify({ 'message_type': "success", 'action': 'noop', 'message': 'Already upto date' }) if form.errors: html = render_template('playlist-extend.html.jinja2', form=form, channel=channel, playlist=playlist) return jsonify({ 'message_type': "error", 'action': 'append', 'html': html }) return jsonify({ 'action': 'modal-window', 'message_type': 'success', 'html': html }) return html
def playlist_extend(channel, playlist): form = PlaylistImportForm() form.channel = channel if request.method == 'GET': html_form = render_form(form=form, title=_("Playlist extend"), submit=_("Save"), cancel_url=playlist.url_for(), ajax=False, with_chrome=False) return {'playlist': dict(playlist.current_access()), 'form': html_form} if form.validate_on_submit(): playlist_url = escape(form.playlist_url.data) initial_count = len(playlist.videos) process_playlist(playlist_url=playlist_url, playlist=playlist) additions = (len(playlist.videos) - initial_count) if additions: db.session.commit() cache.delete('data/featured-channels') return {'status': 'ok', 'doc': _("Added video to playlist {title}.".format(title=playlist.title)), 'result': {}} return {'status': 'error', 'errors': form.errors}, 400
def playlist_import(channel): form = PlaylistImportForm() form.channel = channel if request.method == "GET": html_form = render_form(form=form, title=_("Import Playlist"), submit=_("Import"), cancel_url=channel.url_for(), ajax=True, with_chrome=False) return {'channel': dict(channel.current_access()), 'form': html_form} if form.validate_on_submit(): playlist = Playlist(channel=channel) form.populate_obj(playlist) try: process_playlist(playlist, playlist_url=form.playlist_url.data) if not playlist.name: playlist.make_name() db.session.add(playlist) db.session.commit() cache.delete('data/featured-channels') return {'status': 'ok', 'doc': _("Imported playlist {title}.".format(title=playlist.title)), 'result': {'new_playlist_url': playlist.url_for()}}, 201 except (DataProcessingError, ValueError) as e: return {'status': 'error', 'errors': {'playlist_url': [e.message]}}, 400 return {'status': 'error', 'errors': form.errors}, 400
def playlist_import(channel): # Import playlist form = PlaylistImportForm() form.channel = channel if form.validate_on_submit(): playlist = Playlist(channel=channel) form.populate_obj(playlist) try: process_playlist(playlist, playlist_url=form.playlist_url.data) if not playlist.name: playlist.make_name() db.session.add(playlist) db.session.commit() except (DataProcessingError, ValueError) as e: flash(e.message, category="error") return render_form(form=form, title="Import Playlist", submit=u"Import", cancel_url=channel.url_for(), ajax=False) flash(u"Imported playlist '%s'." % playlist.title, 'success') return render_redirect(playlist.url_for(), code=303) return render_form(form=form, title="Import Playlist", submit=u"Import", cancel_url=channel.url_for(), ajax=False)
def playlist_import(channel): # Import playlist form = PlaylistImportForm() form.channel = channel if form.validate_on_submit(): playlist = Playlist(channel=channel) form.populate_obj(playlist) try: process_playlist(playlist, playlist_url=form.playlist_url.data) if not playlist.name: playlist.make_name() db.session.add(playlist) db.session.commit() cache.delete('data/featured-channels') except (DataProcessingError, ValueError) as e: flash(e.message, category="error") return render_form(form=form, title="Import Playlist", submit=u"Import", cancel_url=channel.url_for(), ajax=False) flash(u"Imported playlist '%s'." % playlist.title, 'success') return render_redirect(playlist.url_for(), code=303) return render_form(form=form, title="Import Playlist", submit=u"Import", cancel_url=channel.url_for(), ajax=False)