Example #1
0
def video_add_speaker(channel, playlist, video):
    """
    Add Speaker to the given video
    """
    form = VideoCsrfForm()
    speaker_buid = request.form.get('speaker_name')
    if speaker_buid and form.validate():
        # look whether user is present in lastuser, if yes proceed
        userinfo = lastuser.getuser_by_userid(speaker_buid)
        if userinfo:
            speaker_channel = Channel.query.filter_by(
                userid=userinfo['userid']).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)
                to_return = {
                    'message': u"Added %s as speaker" % speaker_channel.title,
                    'message_type': 'added',
                    'userid': speaker_channel.userid,
                    'title': speaker_channel.title
                }
            else:
                to_return = {
                    'message':
                    u"%s is already tagged as a speaker on this video" %
                    speaker_channel.title,
                    'message_type':
                    'noop',
                    'userid':
                    speaker_channel.userid,
                    'title':
                    speaker_channel.title
                }
        else:
            to_return = {
                'message':
                'Could not find a user matching that name or email address',
                'message_type': 'failure'
            }
        db.session.commit()
        return jsonify(to_return)
    if form.csrf_token.errors:
        return jsonify(
            message="This page has expired. Please reload and try again.",
            message_type='failure')
    abort(400)
Example #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
Example #3
0
def lastuserauth():
    # Make channels for the user's organizations
    username = g.user.username or g.user.userid
    channel = Channel.query.filter_by(userid=g.user.userid).first()
    if channel is None:
        channel = Channel(userid=g.user.userid,
                          name=g.user.username or g.user.userid,
                          title=g.user.fullname,
                          type=CHANNEL_TYPE.PERSON)
        db.session.add(channel)
    else:
        if channel.name != username:
            channel.name = username
        if channel.title != g.user.fullname:
            channel.title = g.user.fullname
    for org in g.user.organizations_owned():
        channel = Channel.query.filter_by(userid=org['userid']).first()
        if channel is None:
            channel = Channel(userid=org['userid'],
                              name=org['name'],
                              title=org['title'],
                              type=CHANNEL_TYPE.ORGANIZATION)
            db.session.add(channel)
        else:
            if channel.name != org['name']:
                channel.name = org['name']
            if channel.title != org['title']:
                channel.title = org['title']

    db.session.commit()
    return redirect(get_next_url())
Example #4
0
def video_add_speaker(channel, playlist, video):
    """
    Add Speaker to the given video
    """
    form = VideoCsrfForm()
    speaker_buid = request.form.get('speaker_name')
    if speaker_buid and form.validate():
        # look whether user is present in lastuser, if yes proceed
        userinfo = lastuser.getuser_by_userid(speaker_buid)
        if userinfo:
            speaker_channel = Channel.query.filter_by(userid=userinfo['userid']).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)
                to_return = {'message': u"Added %s as speaker" % speaker_channel.title,
                             'message_type': 'added',
                             'userid': speaker_channel.userid,
                             'title': speaker_channel.title}
            else:
                to_return = {'message': u"%s is already tagged as a speaker on this video" % speaker_channel.title,
                             'message_type': 'noop',
                             'userid': speaker_channel.userid,
                             'title': speaker_channel.title}
        else:
            to_return = {'message': 'Could not find a user matching that name or email address',
                         'message_type': 'failure'}
        db.session.commit()
        return jsonify(to_return)
    if form.csrf_token.errors:
        return jsonify(message="This page has expired. Please reload and try again.",
                       message_type='failure')
    abort(400)
Example #5
0
def lastuserauth():
    # Make channels for the user's organizations
    username = g.user.username or g.user.userid
    channel = Channel.query.filter_by(userid=g.user.userid).first()
    if channel is None:
        channel = Channel(userid=g.user.userid,
            name=g.user.username or g.user.userid,
            title=g.user.fullname,
            type=CHANNEL_TYPE.PERSON)
        db.session.add(channel)
    else:
        if channel.name != username:
            channel.name = username
        if channel.title != g.user.fullname:
            channel.title = g.user.fullname
    for org in g.user.organizations_owned():
        channel = Channel.query.filter_by(userid=org['userid']).first()
        if channel is None:
            channel = Channel(userid=org['userid'],
                name=org['name'],
                title=org['title'],
                type=CHANNEL_TYPE.ORGANIZATION)
            db.session.add(channel)
        else:
            if channel.name != org['name']:
                channel.name = org['name']
            if channel.title != org['title']:
                channel.title = org['title']

    db.session.commit()
    return redirect(get_next_url())
Example #6
0
def index():
    livestream = {
        'enable': bool(app.config.get('LIVESTREAM', [])),
        'streams': app.config.get('LIVESTREAM', [])
        }
    channel_dict = []
    for channel in Channel.get_featured():
        channel_dict.append({
            'name': channel.name,
            'title': channel.title,
            'logo':
                url_for('static', filename='thumbnails/' + channel.channel_logo_filename)
                if channel.channel_logo_filename
                else url_for('static', filename='img/sample-logo.png'),
            'banner_url': channel.channel_banner_url if channel.channel_banner_url else "",
            'bio': channel.bio if channel.bio else ''
            })
    return {'channels': channel_dict, 'livestream': livestream}
Example #7
0
def index():
    return render_template('index.html', channels=Channel.get_featured())
Example #8
0
def index():
    return render_template('index.html.jinja2',
                           channels=Channel.get_featured())
Example #9
0
def lastusernotify(user):
    Channel.update_from_user(user, db.session, type_user=CHANNEL_TYPE.PERSON, type_org=CHANNEL_TYPE.ORGANIZATION)
    db.session.commit()
Example #10
0
def lastuserauth():
    Channel.update_from_user(current_auth.user, db.session, type_user=CHANNEL_TYPE.PERSON, type_org=CHANNEL_TYPE.ORGANIZATION)
    db.session.commit()
    return redirect(get_next_url())