Ejemplo n.º 1
0
def playlist_new_modal(channel, video):
    # Make a new playlist
    form = PlaylistForm()
    html = render_template('playlist-modal.html', form=form, channel=channel, video=video)
    if request.is_xhr:
        if form.validate_on_submit():
            playlist = Playlist(channel=channel)
            form.populate_obj(playlist)
            if not playlist.name:
                playlist.make_name()
            db.session.add(playlist)
            db.session.commit()
            if video not in playlist.videos:
                playlist.videos.append(video)
                message = u"Added video to playlist"
                message_type = 'success'
                action = 'append'
            else:
                message = u"This video is already in that playlist"
                message_type = 'info'
                action = 'noop'
            html_to_return = render_template('new-playlist-tag.html', playlist=playlist, channel=channel, video=video)
            db.session.commit()
            return jsonify({'html': html_to_return, 'message_type': message_type, 'action': action,
                'message': message})
        if form.errors:
            html = render_template('playlist-modal.html', form=form, channel=channel, video=video)
            return jsonify({'message_type': "error", 'action': 'append',
                'html': html})
        return jsonify({'html': html, 'message_type': 'success', 'action': 'modal-window'})
    return html
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
def playlist_new_modal(channel, video):
    # Make a new playlist
    form = PlaylistForm()
    html = render_template('playlist-modal.html.jinja2',
                           form=form,
                           channel=channel,
                           video=video)
    if request.is_xhr:
        if form.validate_on_submit():
            playlist = Playlist(channel=channel)
            form.populate_obj(playlist)
            if not playlist.name:
                playlist.make_name()
            db.session.add(playlist)
            stream_playlist = channel.playlist_for_stream(create=True)
            if video not in stream_playlist.videos:
                stream_playlist.videos.append(video)
            if video not in playlist.videos:
                playlist.videos.append(video)
                message = u"Added video to playlist"
                message_type = 'success'
                action = 'append'
            else:
                message = u"This video is already in that playlist"
                message_type = 'info'
                action = 'noop'
            html_to_return = render_template('new-playlist-tag.html.jinja2',
                                             playlist=playlist,
                                             channel=channel,
                                             video=video)
            db.session.commit()
            return jsonify({
                'html': html_to_return,
                'message_type': message_type,
                'action': action,
                'message': message
            })
        if form.errors:
            html = render_template('playlist-modal.html.jinja2',
                                   form=form,
                                   channel=channel,
                                   video=video)
            return jsonify({
                'message_type': "error",
                'action': 'append',
                'html': html
            })
        return jsonify({
            'html': html,
            'message_type': 'success',
            'action': 'modal-window'
        })
    return html
Ejemplo n.º 4
0
def playlist_new(channel):
    # Make a new playlist
    form = PlaylistForm()
    form.channel = channel
    if form.validate_on_submit():
        playlist = Playlist(channel=channel)
        form.populate_obj(playlist)
        if not playlist.name:
            playlist.make_name()
        db.session.add(playlist)
        db.session.commit()
        flash(u"Created playlist '%s'." % playlist.title, 'success')
        return render_redirect(playlist.url_for(), code=303)
    return render_form(form=form, title="New Playlist", submit=u"Create",
        cancel_url=channel.url_for(), ajax=True)
Ejemplo n.º 5
0
def playlist_new(channel):
    if channel.userid not in g.user.user_organization_ids():
        abort(403)
    # Make a new playlist
    form = PlaylistForm()
    form.channel = channel
    if form.validate_on_submit():
        playlist = Playlist(channel=channel)
        form.populate_obj(playlist)
        if not playlist.name:
            playlist.make_name()
        db.session.add(playlist)
        db.session.commit()
        flash(u"Created playlist '%s'." % playlist.title, 'success')
        return render_redirect(url_for('playlist_view', channel=channel.name, playlist=playlist.name), code=303)
    return render_form(form=form, title="New Playlist", submit=u"Create",
        cancel_url=url_for('channel_view', channel=channel.name), ajax=True)
Ejemplo n.º 6
0
def playlist_new(channel):
    # Make a new playlist
    form = PlaylistForm()
    form.channel = channel
    if form.validate_on_submit():
        playlist = Playlist(channel=channel)
        form.populate_obj(playlist)
        if not playlist.name:
            playlist.make_name()
        db.session.add(playlist)
        db.session.commit()
        flash(u"Created playlist '%s'." % playlist.title, 'success')
        return render_redirect(playlist.url_for(), code=303)
    return render_form(form=form,
                       title="New Playlist",
                       submit=u"Create",
                       cancel_url=channel.url_for(),
                       ajax=True)
Ejemplo n.º 7
0
def playlist_new(channel):
    form = PlaylistForm()
    form.channel = channel
    if request.method == 'GET':
        form.published_date.data = date.today()
        html_form = render_form(form=form, title=_("New Playlist"), submit=_("Create"),
        cancel_url=channel.url_for(), ajax=True, with_chrome=False)
        return {'channel': dict(channel.current_access()), 'form': html_form}
    try:
        if form.validate_on_submit():
            playlist = Playlist(channel=channel)
            form.populate_obj(playlist)
            if not playlist.name:
                playlist.make_name()
            db.session.add(playlist)
            db.session.commit()
            return {'status': 'ok', 'doc': _("Created playlist {title}.".format(title=playlist.title)), 'result': {'new_playlist_url': playlist.url_for()}}, 201
        return {'status': 'error', 'errors': form.errors}, 400
    except UploadNotAllowed as e:
        return {'status': 'error', 'errors': [e.message]}, 400
Ejemplo n.º 8
0
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
Ejemplo n.º 9
0
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)
Ejemplo n.º 10
0
def playlist_new_modal(channel, video):
    # Make a new playlist
    form = PlaylistForm()
    if request.method == 'GET':
        html_form = render_form(form=form, title=_("New Playlist"), submit=_("Save"),
        cancel_url=channel.url_for(), ajax=False, 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)
        if not playlist.name:
            playlist.make_name()
        db.session.add(playlist)
        stream_playlist = channel.playlist_for_stream(create=True)
        if video not in stream_playlist.videos:
            stream_playlist.videos.append(video)
        if video not in playlist.videos:
            playlist.videos.append(video)
            message = "Added video to playlist"
        else:
            message = "This video is already in that playlist"
        db.session.commit()
        return {'status': 'ok', 'doc': _(message), 'result': {'new_playlist_url': playlist.url_for()}}, 201
    return {'status': 'error', 'errors': form.errors}, 400
Ejemplo n.º 11
0
def index():
    channels = Channel.query.order_by('featured').order_by('updated_at').limit(3).all()
    playlists = Playlist.get_featured(3)
    return render_template('index.html', channels=channels, playlists=playlists)
Ejemplo n.º 12
0
def index():
    playlists = Playlist.get_featured(10)
    return render_template('index.html', playlists=playlists)