Exemplo n.º 1
0
def video_new(channel, playlist):
    """
    Add a new video
    """
    form = VideoAddForm()
    if request.method == 'GET':
        if playlist is None:
            cancel_url = channel.url_for()
        else:
            cancel_url = playlist.url_for()
        html_form = render_form(form=form, title=_("New Video"), submit=_("Add"),
                           cancel_url=cancel_url, ajax=False, with_chrome=False)
        return {'channel': dict(channel.current_access()), 'playlist': dict(playlist.current_access()), 'form': html_form}
    if form.validate_on_submit():
        stream_playlist = channel.playlist_for_stream(create=True)
        video = Video(playlist=playlist if playlist is not None else stream_playlist)
        form.populate_obj(video)
        try:
            process_video(video, new=True)
            process_slides(video)
        except (DataProcessingError, ValueError) as e:
            return {'status': 'error', 'errors': {'video_url': [e.message]}}, 400
        video.make_name()
        if playlist is not None and video not in playlist.videos:
            playlist.videos.append(video)
        if video not in stream_playlist.videos:
            stream_playlist.videos.append(video)
        db.session.commit()
        return {'status': 'ok', 'doc': _("Added video {title}.".format(title=video.title)), 'result': {'new_video_edit_url': video.url_for('edit')}}, 201
    else:
        return {'status': 'error', 'errors': form.errors}, 400
Exemplo n.º 2
0
def add_new_video(channel, playlist):
    form = VideoAddForm()
    if form.validate_on_submit():
        stream_playlist = channel.playlist_for_stream(create=True)
        video = Video(playlist=playlist if playlist is not None else stream_playlist)
        form.populate_obj(video)
        try:
            process_video(video, new=True)
            process_slides(video)
        except (DataProcessingError, ValueError) as e:
            flash(e.message, category="error")
            return render_form(form=form, title=u"New Video", submit=u"Add",
                               cancel_url=channel.url_for(), ajax=False)
        video.make_name()
        if playlist is not None and video not in playlist.videos:
            playlist.videos.append(video)
        if video not in stream_playlist.videos:
            stream_playlist.videos.append(video)
        db.session.commit()
        flash(u"Added video '%s'." % video.title, 'success')
        return render_redirect(video.url_for('edit'))
    if playlist is None:
        cancel_url = channel.url_for()
    else:
        cancel_url = playlist.url_for()
    return render_form(form=form, title=u"New Video", submit=u"Add",
                       cancel_url=cancel_url, ajax=False)
Exemplo n.º 3
0
def add_new_video(channel, playlist):
    form = VideoAddForm()
    if form.validate_on_submit():
        stream_playlist = channel.playlist_for_stream(create=True)
        video = Video(
            playlist=playlist if playlist is not None else stream_playlist)
        form.populate_obj(video)
        try:
            process_video(video, new=True)
            process_slides(video)
        except (DataProcessingError, ValueError) as e:
            flash(e.message, category="error")
            return render_form(form=form,
                               title=u"New Video",
                               submit=u"Add",
                               cancel_url=channel.url_for(),
                               ajax=False)
        video.make_name()
        if playlist is not None and video not in playlist.videos:
            playlist.videos.append(video)
        if video not in stream_playlist.videos:
            stream_playlist.videos.append(video)
        db.session.commit()
        flash(u"Added video '%s'." % video.title, 'success')
        return render_redirect(video.url_for('edit'))
    if playlist is None:
        cancel_url = channel.url_for()
    else:
        cancel_url = playlist.url_for()
    return render_form(form=form,
                       title=u"New Video",
                       submit=u"Add",
                       cancel_url=cancel_url,
                       ajax=False)
Exemplo n.º 4
0
def video_new(channel, playlist):
    """
    Add a new video
    """
    form = VideoAddForm()
    if form.validate_on_submit():
        video = Video(playlist=playlist)
        form.populate_obj(video)
        try:
            process_video(video, new=True)
            process_slides(video)
        except (DataProcessingError, ValueError) as e:
            flash(e.message, category="error")
            return render_form(form=form,
                               title=u"New Video",
                               submit=u"Add",
                               cancel_url=playlist.url_for(),
                               ajax=False)
        video.make_name()
        playlist.videos.append(video)
        db.session.commit()
        flash(u"Added video '%s'." % video.title, 'success')
        return render_redirect(video.url_for('edit'))
    return render_form(form=form,
                       title=u"New Video",
                       submit=u"Add",
                       cancel_url=playlist.url_for(),
                       ajax=False)
Exemplo n.º 5
0
def video_new(channel, playlist):
    """
    Add a new video
    """
    form = VideoAddForm()
    if form.validate_on_submit():
        video = Video(playlist=playlist)
        form.populate_obj(video)
        try:
            process_video(video, new=True)
            process_slides(video)
        except (DataProcessingError, ValueError) as e:
            flash(e.message, category="error")
            return render_form(form=form, title=u"New Video", submit=u"Add",
                cancel_url=playlist.url_for(), ajax=False)
        video.make_name()
        playlist.videos.append(video)
        db.session.commit()
        flash(u"Added video '%s'." % video.title, 'success')
        return render_redirect(video.url_for('edit'))
    return render_form(form=form, title=u"New Video", submit=u"Add",
        cancel_url=playlist.url_for(), ajax=False)
Exemplo n.º 6
0
def video_new(channel, playlist):
    """
    Add a new video
    """
    if channel.userid not in g.user.user_organization_ids():
        """
        User doesn't own this playlist
        """
        abort(403)

    form = VideoAddForm()
    if form.validate_on_submit():
        video = Video(playlist=playlist)
        form.populate_obj(video)
        video.process_video()
        video.process_slides()
        video.make_name()
        db.session.add(video)
        playlist.videos.append(video)
        db.session.commit()
        flash(u"Added video '%s'." % video.title, 'success')
        return render_redirect(url_for('video_view', channel=channel.name, playlist=playlist.name, video=video.url_name))
    return render_form(form=form, title="New Video", submit="Add", cancel_url=url_for('channel_view', channel=channel.name), ajax=False)