def trim_video(vid_id): """Load form to get user clip requests""" vid_to_trim = Video.query.get(vid_id) vid_name = vid_to_trim.vid_name case_id = vid_to_trim.case.case_id has_transcript = False if vid_to_trim.transcript: has_transcript = True # check if user is permitted to see this content user_permitted = validate_usercase(case_id, g.current_user.user_id) if user_permitted: # get temporary url url = get_vid_url(vid_name) return render_template('trim-form.html', vid_id=vid_id, orig_vid=vid_name, vid_url=url, has_transcript=has_transcript) else: flash("You don't have permission to view that case") return redirect('/cases')
def send_casemessage(json_data): """Posts a message on the case settings page""" data = json.loads(json_data) case_id = data['case_id'] # check if the user has permission to view this case user_permitted = validate_usercase(case_id, g.current_user.user_id) if user_permitted: mess_text = data['new_mess'] new_mess = CaseMessage(user_id=g.current_user.user_id, case_id=case_id, text=mess_text) db.session.add(new_mess) db.session.commit() response = { 'user_name': g.current_user.fname + " " + g.current_user.lname, 'mess_text': mess_text, 'mess_id': new_mess.mess_id, 'user_id': g.current_user.user_id, } emit('new casemessage', response, namespace='/chat', room=case_id) return jsonify(response)
def get_clip_source(): """Created clips in db - threads to download, pull_text, and make-clips functions""" # get video obj from db vid_id = request.form.get('vid_id') vid_to_trim = Video.query.get(vid_id) vid_name = vid_to_trim.vid_name case_id = vid_to_trim.case.case_id #get the user id user_id = g.current_user.user_id user_permitted = validate_usercase(case_id, user_id) if user_permitted: # get the clip list from the form clip_list = request.form.get('clip-list') clips = clip_list.split(", ") print "clips:", clips # get if the user is using timecodes or page-line nums trim_method = request.form.get('trim_method') # make pathname for location to save temp video save_loc = 'static/temp/' + vid_name # trim path to remove the file ext clip_name_base = save_loc[0:-4] # using mov as native file type as it seems to work the most consistently file_ext = ".mov" # make a list to hold the clip db objects clips_to_process = [] # add the clips to the db - they will show up as processing until they are complete for clip in clips: print clip_name_base # creates an instance of the clip in the db and returns new clip_id # if the clip exists already - None is returned db_clip = add_clip_to_db(clip, clip_name_base, file_ext, vid_id, user_id, trim_method) # if a new clip was made if db_clip: clips_to_process.append(Clip.query.get(db_clip)) print clips_to_process # send the upload to a separate thread to upload while the user moves on download = threading.Thread(target=download_from_aws, args=(save_loc, clips_to_process, vid_id, user_id, vid_name, socketio)).start() return redirect('/clips/{}'.format(vid_id)) else: flash("You don't have permission to view that case") return redirect('/cases')
def remove_user_from_case(): """Removes a user from a specific case""" # get data case_id = request.form.get('case_id') user_id = request.form.get('del_user') # use validate usercase to return the usercase obj for this user/case usercase = validate_usercase(case_id, user_id) db.session.delete(usercase) db.session.commit() return "Usercase removed"
def show_case_settings(case_id): """Shows user settings for chosen case""" # check if the user has permission to view this case user_permitted = validate_usercase(case_id, g.current_user.user_id) case = Case.query.get(case_id) owner_id = case.owner_id owner = User.query.get(owner_id) if user_permitted: # get all users associated with this case id users = db.session.query(User.fname, User.lname, User.email, User.user_id).join(UserCase).filter( UserCase.case_id == case_id).order_by( User.fname).all() # get the tags for this case and the default tags tags = get_tags(case_id) tag_counts = {} for tag in tags: # get tagged clips returns a list of clip ids - convert to a string # and it will be used as a value on a download link tag.matching_clips = get_tagged_clips(tag, case_id) # count the clip ids to get a total count tag_counts[tag.tag_name] = len(tag.matching_clips) # convert the list to a string to use as a value on the button # we do this bc the handle-clips route parses a string into a tag.matching_clips = str(tag.matching_clips)[1:-1] case_mess = CaseMessage.query.filter( CaseMessage.case_id == case_id).order_by( CaseMessage.mess_id.desc()).all() return render_template('case-settings.html', users=users, case=case, tags=tags, owner=owner, tag_counts=tag_counts, case_mess=case_mess) else: flash("You don't have permission to view that case") return redirect('/cases')
def show_tscript(vid_id): """Shows transcript for selected video""" vid = Video.query.get(vid_id) print vid.case_id, g.current_user.user_id user_permitted = validate_usercase(vid.case_id, g.current_user.user_id) if user_permitted: tscript_obj = Transcript.query.filter( Transcript.vid_id == vid_id).first() tscript = tscript_obj.text tscript = tscript.split('\n","\n') return render_template('/tscript-preview.html', tscript=tscript, vid_id=vid_id)
def show_case_vids(case_id): """Show all full videos associated with this case""" user_permitted = validate_usercase(case_id, g.current_user.user_id) if user_permitted: # get all videos that match the provided case_id vids = Video.query.filter(Video.case_id == case_id).order_by( Video.vid_name).all() # get the case object for the provided case_id this_case = Case.query.get(case_id) for vid in vids: vid.recorded_at = datetime.strftime(vid.recorded_at, '%Y-%m-%d') return render_template('case-vids.html', videos=vids, case=this_case) else: flash("You don't have permission to view that case") return redirect('/cases')
def show_all_clips(vid_id): """loads page with a list of all clips for that vid id""" #get a list of all the clips associated with that video id main_vid = Video.query.get(vid_id) case_id = main_vid.case.case_id user_permitted = validate_usercase(case_id, g.current_user.user_id) if user_permitted: clips = Clip.query.filter(Clip.vid_id == vid_id).all() for clip in clips: # get the clip duration # if the time includes milliseconds - trim them off if clip.start_at is not None: start_time = clip.start_at if len(start_time) > 8: clip.start_at = start_time = start_time[:-4] end_time = clip.end_at if len(end_time) > 8: clip.end_at = end_time = end_time[:-4] start_at = datetime.strptime(start_time, '%H:%M:%S') end_at = datetime.strptime(end_time, '%H:%M:%S') clip.duration = end_at - start_at else: clip.duration = '--' # get the tags for this case and the default tags tags = get_tags(main_vid.case_id) return render_template('vid-clips.html', main_vid=main_vid, clips=clips, tags=tags) else: flash("You don't have permission to view that case") return redirect('/cases')
def show_video(vid_id): """Streams the selected video""" #get the video object vid_to_trim = Video.query.get(vid_id) vid_name = vid_to_trim.vid_name case_id = vid_to_trim.case.case_id user_permitted = validate_usercase(case_id, g.current_user.user_id) if user_permitted: # get temporary url for that video url = get_vid_url(vid_name) return render_template('show-video.html', vid_id=vid_id, orig_vid=vid_name, vid_url=url) else: flash("You don't have permission to view that case") return redirect('/cases')
def show_clip(clip_id): """Plays the clip in a separate window""" # get the clip object clip_to_show = Clip.query.get(clip_id) clip_name = clip_to_show.clip_name # get the case id associated with this clip case_id = clip_to_show.video.case.case_id user_permitted = validate_usercase(case_id, g.current_user.user_id) if user_permitted: # get temporary url url = get_vid_url(clip_name) return render_template('show-video.html', vid_id=clip_id, orig_vid=clip_name, vid_url=url) else: flash("You don't have permission to view that case") return redirect('/cases')
def show_case_messages(case_id): """Shows messages for chosen case""" # check if the user has permission to view this case user_permitted = validate_usercase(case_id, g.current_user.user_id) case = Case.query.get(case_id) owner_id = case.owner_id owner = User.query.get(owner_id) if user_permitted: # get the case messages for this case case_mess = CaseMessage.query.filter( CaseMessage.case_id == case_id).order_by( CaseMessage.mess_id.desc()).all() return render_template('case-messages.html', case=case, owner=owner, case_mess=case_mess) else: flash("You don't have permission to view that case") return redirect('/cases')