Beispiel #1
0
def video_edit(channel, playlist, video, kwargs):
    """
    Edit video
    """
    if video.channel.userid not in g.user.user_organization_ids():
        # User isn't authorized to edit
        abort(403)

    if playlist != video.playlist:
        # This video isn't in this playlist. Redirect to canonical URL
        return redirect(url_for('video_edit', channel=video.channel.name, playlist=video.playlist.name, video=video.url_name))

    if kwargs['video'] != video.url_name:
        # Video's URL has changed. Redirect user to prevent old/invalid names
        # showing in the URL
        return redirect(url_for('video_delete', channel=channel.name, playlist=playlist.name, video=video.url_name))

    form = VideoEditForm(obj=video)
    if form.validate_on_submit():
        form.populate_obj(video)
        video.process_slides()
        db.session.commit()
        flash(u"Edited 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=u"Edit video", submit=u"Save",
        cancel_url=url_for('video_view', channel=channel.name, playlist=playlist.name, video=video.url_name),
        ajax=True)
Beispiel #2
0
def video_edit(channel, playlist, video):
    """
    Edit video
    """
    current_speakers = [speaker.userid for speaker in video.speakers]
    form = VideoEditForm(obj=video)
    if request.method == 'GET':
        html_form = render_form(form=form, title=_("Edit Video"), submit=_("Save"),
            cancel_url=video.url_for(), ajax=False, with_chrome=False)
        return {'video': dict(video.current_access()), 'form': html_form}
    if form.validate():
        form.populate_obj(video)
        if not video.name:
            video.make_name()
        if video.video_url != form.video_url.data:
            try:
                process_video(video, new=False)
            except (DataProcessingError, ValueError) as e:
                return {'status': 'error', 'errors': {'video_url': [e.message]}}, 400
        if video.slides_url != form.slides_url.data:
            try:
                process_slides(video)
                if video.video_slides_mapping:
                    video.video_slides_mapping_json = make_presentz_json(video, json.loads(video.video_slides_mapping))
            except (DataProcessingError, ValueError) as e:
                return {'status': 'error', 'errors': {'slides_url': [e.message]}}, 400
        new_speakers = [new_speaker.userid for new_speaker in form.speakers.data]
        for current_speaker in current_speakers:
            # Remove speaker
            if current_speaker not in new_speakers:
                speaker_channel = Channel.query.filter_by(userid=current_speaker).first()
                if speaker_channel:
                    speaker_playlist = speaker_channel.playlist_for_speaking_in()
                    if speaker_playlist:
                        speaker_playlist.videos.remove(video)
        for new_speaker in new_speakers:
            # Add speaker
            if new_speaker not in current_speakers:
                userinfo = lastuser.getuser_by_userid(new_speaker)
                if userinfo:
                    speaker_channel = Channel.query.filter_by(userid=new_speaker).first()
                    if speaker_channel is None:
                        # Create a channel for this speaker. They have never logged in to hasgeek.tv
                        # at this point, but when they do, the channel will be waiting for them
                        speaker_channel = Channel(userid=userinfo['userid'], name=userinfo['name'] or userinfo['userid'],
                            title=userinfo['title'], type=CHANNEL_TYPE.PERSON)
                        db.session.add(speaker_channel)
                    else:
                        speaker_channel.title = userinfo['title']
                        speaker_channel.name = userinfo['name'] or userinfo['userid']
                    speaker_playlist = speaker_channel.playlist_for_speaking_in(create=True)
                    if video not in speaker_playlist.videos:
                        speaker_playlist.videos.append(video)
                else:
                    return {'status': 'error', 'errors': ['Could not find a user matching that name or email address']}, 400
        db.session.commit()
        return {'status': 'ok', 'doc': _("Edited video {title}.".format(title=video.title)), 'result': {}}, 201
    return {'status': 'error', 'errors': form.errors}, 400
Beispiel #3
0
def video_edit(channel, playlist, video):
    """
    Edit video
    """
    if playlist != video.playlist:
        # This video isn't in this playlist. Redirect to canonical URL
        return redirect(video.url_for('edit'))

    form = VideoEditForm(obj=video)
    formvideo = VideoVideoForm(obj=video)
    formslides = VideoSlidesForm(obj=video)
    form_id = request.form.get('form.id')
    if request.method == "POST":
        if form_id == u'video':  # check whether done button is clicked
            if form.validate_on_submit():
                form.populate_obj(video)
                video.make_name()
                db.session.commit()
                flash(u"Edited video '%s'." % video.title, 'success')
                return render_redirect(video.url_for(), code=303)
        elif form_id == u'video_url':  # check video_url was updated
            if formvideo.validate_on_submit():
                formvideo.populate_obj(video)
                process_video(video, new=False)
                db.session.commit()
                return render_redirect(video.url_for('edit'), code=303)
        elif form_id == u'slide_url':  # check slides_url was updated
            if formslides.validate_on_submit():
                formslides.populate_obj(video)
                process_slides(video)
                db.session.commit()
                return render_redirect(video.url_for('edit'), code=303)
    speakers = [
        plv.playlist.channel
        for plv in PlaylistVideo.query.filter_by(video=video)
        if plv.playlist.auto_type == PLAYLIST_AUTO_TYPE.SPEAKING_IN
    ]
    return render_template('videoedit.html',
                           channel=channel,
                           playlist=playlist,
                           video=video,
                           form=form,
                           formvideo=formvideo,
                           formslides=formslides,
                           speakers=speakers)
Beispiel #4
0
def video_edit(channel, playlist, video):
    """
    Edit video
    """
    if playlist != video.playlist:
        # This video isn't in this playlist. Redirect to canonical URL
        return redirect(video.url_for('edit'))

    form = VideoEditForm(obj=video)
    formvideo = VideoVideoForm(obj=video)
    formslides = VideoSlidesForm(obj=video)
    form_id = request.form.get('form.id')
    if request.method == "POST":
        if form_id == u'video':  # check whether done button is clicked
            if form.validate_on_submit():
                form.populate_obj(video)
                video.make_name()
                db.session.commit()
                flash(u"Edited video '%s'." % video.title, 'success')
                return render_redirect(video.url_for(), code=303)
        elif form_id == u'video_url':  # check video_url was updated
            if formvideo.validate_on_submit():
                formvideo.populate_obj(video)
                process_video(video, new=False)
                db.session.commit()
                return render_redirect(video.url_for('edit'), code=303)
        elif form_id == u'slide_url':  # check slides_url was updated
            if formslides.validate_on_submit():
                formslides.populate_obj(video)
                process_slides(video)
                db.session.commit()
                return render_redirect(video.url_for('edit'), code=303)
    speakers = [plv.playlist.channel for plv in PlaylistVideo.query.filter_by(video=video) if plv.playlist.auto_type == PLAYLIST_AUTO_TYPE.SPEAKING_IN]
    return render_template('videoedit.html',
        channel=channel,
        playlist=playlist,
        video=video,
        form=form,
        formvideo=formvideo,
        formslides=formslides,
        speakers=speakers)
Beispiel #5
0
def video_edit(channel, playlist, video):
    """
    Edit video
    """
    if playlist != video.playlist:
        # This video isn't in this playlist. Redirect to canonical URL
        return redirect(video.url_for('edit'))

    form = VideoEditForm(obj=video)
    formvideo = VideoVideoForm(obj=video)
    formslides = VideoSlidesForm(obj=video)
    formsync = VideoSlidesSyncForm(obj=video)
    form_id = request.form.get('form.id')
    if request.method == "POST":
        if form_id == u'video':  # check whether done button is clicked
            if form.validate_on_submit():
                form.populate_obj(video)
                video.make_name()
                db.session.commit()
                flash(u"Edited video '%s'." % video.title, 'success')
                return render_redirect(video.url_for(), code=303)
        elif form_id == u'video_url':  # check video_url was updated
            if formvideo.validate_on_submit():
                formvideo.populate_obj(video)
                try:
                    process_video(video, new=False)
                except (DataProcessingError, ValueError) as e:
                    flash(e.message, category="error")
                db.session.commit()
                return render_redirect(video.url_for('edit'), code=303)
        elif form_id == u'slide_url':  # check slides_url was updated
            if formslides.validate_on_submit():
                formslides.populate_obj(video)
                try:
                    process_slides(video)
                    if video.video_slides_mapping:
                        video.video_slides_mapping_json = make_presentz_json(video, json.loads(video.video_slides_mapping))
                except (DataProcessingError, ValueError) as e:
                    flash(e.message, category="error")
                db.session.commit()
                return render_redirect(video.url_for('edit'), code=303)
        elif form_id == u'video_slides_sync':
            if formsync.validate_on_submit():
                formsync.populate_obj(video)
                try:
                    if video.video_slides_mapping:
                        video.video_slides_mapping_json = make_presentz_json(video, json.loads(video.video_slides_mapping))
                    else:
                        flash(u"No value found for syncing video and slides", "error")
                except ValueError:
                    flash(u"SyntaxError in video slides mapping value", "error")
                db.session.commit()
                return render_redirect(video.url_for('edit'), code=303)

    speakers = [plv.playlist.channel for plv in PlaylistVideo.query.filter_by(video=video) if plv.playlist.auto_type == PLAYLIST_AUTO_TYPE.SPEAKING_IN]
    return render_template('videoedit.html',
        channel=channel,
        playlist=playlist,
        video=video,
        form=form,
        formvideo=formvideo,
        formslides=formslides,
        formsync=formsync,
        speakers=speakers,
        autocomplete_url=lastuser.endpoint_url(lastuser.getuser_autocomplete_endpoint),
        slideshare_unique_value=get_slideshare_unique_value(video.slides_url) if video.slides_source == u'slideshare' else None)
Beispiel #6
0
def video_edit(channel, playlist, video):
    """
    Edit video
    """
    if playlist != video.playlist:
        # This video isn't in this playlist. Redirect to canonical URL
        return redirect(video.url_for('edit'))

    form = VideoEditForm(obj=video)
    formvideo = VideoVideoForm(obj=video)
    formslides = VideoSlidesForm(obj=video)
    formsync = VideoSlidesSyncForm(obj=video)
    form_id = request.form.get('form.id')
    if request.method == "POST":
        if form_id == u'video':  # check whether done button is clicked
            if form.validate_on_submit():
                form.populate_obj(video)
                video.make_name()
                db.session.commit()
                flash(u"Edited video '%s'." % video.title, 'success')
                return render_redirect(video.url_for(), code=303)
        elif form_id == u'video_url':  # check video_url was updated
            if formvideo.validate_on_submit():
                formvideo.populate_obj(video)
                try:
                    process_video(video, new=False)
                except (DataProcessingError, ValueError) as e:
                    flash(e.message, category="error")
                db.session.commit()
                return render_redirect(video.url_for('edit'), code=303)
        elif form_id == u'slide_url':  # check slides_url was updated
            if formslides.validate_on_submit():
                formslides.populate_obj(video)
                try:
                    process_slides(video)
                    if video.video_slides_mapping:
                        video.video_slides_mapping_json = make_presentz_json(
                            video, json.loads(video.video_slides_mapping))
                except (DataProcessingError, ValueError) as e:
                    flash(e.message, category="error")
                db.session.commit()
                return render_redirect(video.url_for('edit'), code=303)
        elif form_id == u'video_slides_sync':
            if formsync.validate_on_submit():
                formsync.populate_obj(video)
                try:
                    if video.video_slides_mapping:
                        video.video_slides_mapping_json = make_presentz_json(
                            video, json.loads(video.video_slides_mapping))
                    else:
                        flash(u"No value found for syncing video and slides",
                              "error")
                except ValueError:
                    flash(u"SyntaxError in video slides mapping value",
                          "error")
                db.session.commit()
                return render_redirect(video.url_for('edit'), code=303)

    speakers = [
        plv.playlist.channel
        for plv in PlaylistVideo.query.filter_by(video=video)
        if plv.playlist.auto_type == PLAYLIST_AUTO_TYPE.SPEAKING_IN
    ]
    return render_template(
        'videoedit.html.jinja2',
        channel=channel,
        playlist=playlist,
        video=video,
        form=form,
        formvideo=formvideo,
        formslides=formslides,
        formsync=formsync,
        speakers=speakers,
        autocomplete_url=lastuser.endpoint_url(
            lastuser.getuser_autocomplete_endpoint),
        slideshare_unique_value=get_slideshare_unique_value(video.slides_url)
        if video.slides_source == u'slideshare' else None)