Example #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
Example #2
0
def playlist_edit(channel, playlist):
    form = PlaylistForm(obj=playlist)
    form.channel = channel
    if form.validate_on_submit():
        form.populate_obj(playlist)
        db.session.commit()
        flash(u"Edited playlist '%s'" % playlist.title, 'success')
        return render_redirect(playlist.url_for(), code=303)
    return render_form(form=form, title="Edit Playlist", submit=u"Save",
        cancel_url=playlist.url_for(), ajax=True)
Example #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
Example #4
0
def playlist_edit(channel, playlist):
    if channel.userid not in g.user.user_organization_ids():
        abort(403)
    form = PlaylistForm(obj=playlist)
    form.channel = channel
    if form.validate_on_submit():
        form.populate_obj(playlist)
        db.session.commit()
        flash(u"Edited 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="Edit Playlist", submit=u"Save",
        cancel_url=url_for('playlist_view', channel=channel.name, playlist=playlist.name), ajax=True)
Example #5
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)
Example #6
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)
Example #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
Example #8
0
def playlist_edit(channel, playlist):
    form = PlaylistForm(obj=playlist)
    form.channel = channel
    if not playlist.banner_ad_filename:
        del form.delete_banner_ad
    message = None
    old_playlist_banner_ad_filename = playlist.banner_ad_filename
    old_playlist_name = playlist.name
    try:
        if form.validate_on_submit():
            form.populate_obj(playlist)
            if not playlist.name:
                playlist.make_name()
            playlist.banner_ad = playlist.banner_image
            if old_playlist_name != playlist.name:
                redirect_to = PlaylistRedirect.query.filter_by(name=old_playlist_name, channel=channel).first()
                if redirect_to:
                    redirect_to.playlist = playlist
                else:
                    redirect_to = PlaylistRedirect(name=old_playlist_name, channel=channel, playlist=playlist)
                    db.session.add(redirect_to)
            if playlist.banner_ad:
                if playlist.banner_ad_filename != old_playlist_banner_ad_filename:
                    remove_banner_ad(old_playlist_banner_ad_filename)
                flash(u"Added new banner ad", u"success")
                playlist.banner_ad_filename = thumbnails.save(return_werkzeug_filestorage(playlist.banner_ad, playlist.title))
                message = True
            if form.delete_banner_ad and form.delete_banner_ad.data:
                flash(u"Removed banner ad", u"success")
                message = True
                db.session.add(playlist)
                remove_banner_ad(playlist.banner_ad_filename)
                playlist.banner_ad_filename = None
                playlist.banner_ad_url = ""
            db.session.commit()
            if not message:
                flash(u"Edited playlist '%s'" % playlist.title, 'success')
            return render_redirect(playlist.url_for(), code=303)
    except UploadNotAllowed, e:
        flash(e.message, u'error')
Example #9
0
def playlist_edit(channel, playlist):
    form = PlaylistForm(obj=playlist)
    form.channel = channel
    if request.method == 'GET':
        html_form = render_form(form=form, title=_("Edit Playlist"), submit=_("Save"),
            cancel_url=playlist.url_for(), ajax=False, with_chrome=False)
        return {'playlist': dict(playlist.current_access()), 'form': html_form}
    if not playlist.banner_ad_filename:
        del form.delete_banner_ad
    old_playlist_banner_ad_filename = playlist.banner_ad_filename
    old_playlist_name = playlist.name
    try:
        if form.validate_on_submit():
            form.populate_obj(playlist)
            if not playlist.name:
                playlist.make_name()
            playlist.banner_ad = playlist.banner_image
            if old_playlist_name != playlist.name:
                redirect_to = PlaylistRedirect.query.filter_by(name=old_playlist_name, channel=channel).first()
                if redirect_to:
                    redirect_to.playlist = playlist
                else:
                    redirect_to = PlaylistRedirect(name=old_playlist_name, channel=channel, playlist=playlist)
                    db.session.add(redirect_to)
            if playlist.banner_ad:
                if playlist.banner_ad_filename != old_playlist_banner_ad_filename:
                    remove_banner_ad(old_playlist_banner_ad_filename)
                playlist.banner_ad_filename = thumbnails.save(return_werkzeug_filestorage(playlist.banner_ad, playlist.title))
            if form.delete_banner_ad and form.delete_banner_ad.data:
                db.session.add(playlist)
                remove_banner_ad(playlist.banner_ad_filename)
                playlist.banner_ad_filename = None
                playlist.banner_ad_url = ""
            db.session.commit()
            return {'status': 'ok', 'doc': _("Edited playlist {title}.".format(title=playlist.title)), 'result': {'url': playlist.url_for()}}, 200
        return {'status': 'error', 'errors': form.errors}, 400
    except UploadNotAllowed as e:
        return {'status': 'error', 'errors': {'error': [e.message]}}, 400
Example #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
Example #11
0
def playlist_edit(channel, playlist):
    form = PlaylistForm(obj=playlist)
    form.channel = channel
    if form.validate_on_submit():
        form.populate_obj(playlist)
        db.session.commit()
        flash(u"Edited playlist '%s'" % playlist.title, 'success')
        return render_redirect(playlist.url_for(), code=303)
    return render_form(form=form,
                       title="Edit Playlist",
                       submit=u"Save",
                       cancel_url=playlist.url_for(),
                       ajax=True)
Example #12
0
def playlist_edit(channel, playlist):
    form = PlaylistForm(obj=playlist)
    form.channel = channel
    if not playlist.banner_ad_filename:
        del form.delete_banner_ad
    message = None
    old_playlist_banner_ad_filename = playlist.banner_ad_filename
    old_playlist_name = playlist.name
    try:
        if form.validate_on_submit():
            form.populate_obj(playlist)
            if not playlist.name:
                playlist.make_name()
            playlist.banner_ad = playlist.banner_image
            if old_playlist_name != playlist.name:
                redirect_to = PlaylistRedirect.query.filter_by(
                    name=old_playlist_name, channel=channel).first()
                if redirect_to:
                    redirect_to.playlist = playlist
                else:
                    redirect_to = PlaylistRedirect(name=old_playlist_name,
                                                   channel=channel,
                                                   playlist=playlist)
                    db.session.add(redirect_to)
            if playlist.banner_ad:
                if playlist.banner_ad_filename != old_playlist_banner_ad_filename:
                    remove_banner_ad(old_playlist_banner_ad_filename)
                flash(u"Added new banner ad", u"success")
                playlist.banner_ad_filename = thumbnails.save(
                    return_werkzeug_filestorage(playlist.banner_ad,
                                                playlist.title))
                message = True
            if form.delete_banner_ad and form.delete_banner_ad.data:
                flash(u"Removed banner ad", u"success")
                message = True
                db.session.add(playlist)
                remove_banner_ad(playlist.banner_ad_filename)
                playlist.banner_ad_filename = None
                playlist.banner_ad_url = ""
            db.session.commit()
            if not message:
                flash(u"Edited playlist '%s'" % playlist.title, 'success')
            return render_redirect(playlist.url_for(), code=303)
    except UploadNotAllowed, e:
        flash(e.message, u'error')
Example #13
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)