def video_playlist_add(channel, playlist, video): form = VideoCsrfForm() if form.validate_on_submit(): # CSRF check passed if video not in playlist.videos: playlist.videos.append(video) db.session.commit() cache.delete('data/featured-channels') message = u"Added video to playlist" message_type = 'success' action = 'add' else: message = u"This video is already in that playlist" message_type = 'info' action = 'noop' else: message = u"CSRF validation failed. Please reload this page and try again." message_type = 'error' if request.is_xhr: return jsonify(message=message, message_type=message_type, action=action, playlist_name=playlist.name) else: flash(message, message_type) if message_type == 'success': return redirect(video.url_for('view', channel=channel, playlist=playlist)) else: return redirect(video.url_for('view'))
def video_remove_speaker(channel, playlist, video): """ Delete Speaker to the given video """ form = VideoCsrfForm() speaker_userid = request.form.get('speaker_userid') if speaker_userid and form.validate(): speaker_channel = Channel.query.filter_by(userid=speaker_userid).first() if speaker_channel: speaker_playlist = speaker_channel.playlist_for_speaking_in() if speaker_playlist: speaker_playlist.videos.remove(video) to_return = {'message': u"Removed speaker %s" % speaker_channel.title, 'message_type': 'removed', 'userid': speaker_channel.userid, 'title': speaker_channel.title} else: to_return = {'message': u"%s is not tagged as speaker for this video" % speaker_channel.title, 'message_type': 'failure'} db.session.commit() else: to_return = {'message': u"No such speaker", 'message_type': 'failure'} 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)
def video_playlist_add(channel, playlist, video): form = VideoCsrfForm() if form.validate_on_submit(): # CSRF check passed if video not in playlist.videos: playlist.videos.append(video) db.session.commit() cache.delete('data/featured-channels') message = u"Added video to playlist" message_type = 'success' action = 'add' else: message = u"This video is already in that playlist" message_type = 'info' action = 'noop' else: message = u"CSRF validation failed. Please reload this page and try again." message_type = 'error' if request.is_xhr: return jsonify(message=message, message_type=message_type, action=action, playlist_name=playlist.name) else: flash(message, message_type) if message_type == 'success': return redirect( video.url_for('view', channel=channel, playlist=playlist)) else: return redirect(video.url_for('view'))
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)
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)