def get_performance(performance): kwargs = {} if request.args.get("full"): kwargs.update(dict(use="full")) return jsonify(performance=Performance.dump(performance, **kwargs))
def get_performances(recording_platform): kwargs = {} if request.args.get("full"): kwargs.update(dict(use="full")) return jsonify(performances=Performance.dump( recording_platform.performances, **kwargs))
def get_sub_task_performances(sub_task): kwargs = {} performances = [] if request.args.get("full"): kwargs.update(dict(use="full")) for batch in sub_task.batches: for page in batch.pages: for page_member in page.members: performance = Performance.query.get(page_member.raw_piece_id) performances.append(performance) return jsonify(performances=Performance.dump(performances, **kwargs))
def upload_performance_list(recording_platform): data = MyForm( Field("changeMethod", is_mandatory=True, validators=[AudioCheckingChangeMethod.is_valid]), Field("subTaskId", is_mandatory=True, validators=[SubTask.check_exists]), Field("performanceNames", is_mandatory=True, validators=[ validators.is_list, ]), ).get_data() destination = SubTask.query.get(data["subTaskId"]) performances = [] for performance_name in data["performanceNames"]: # TODO handle exception performance = Performance.query.filter_by( recording_platform=recording_platform, name=performance_name).one() performances.append(performance) moved, at_destination, no_transition, locked = recording_platform.move_performances( performances, destination, session["current_user"].user_id, data["changeMethod"]) db.session.flush() return jsonify({ "atDestination": len(at_destination), "noTransition": len(no_transition), "moved": len(moved), "locked": len(locked), "performances": Performance.dump(performances, use="full"), })
def move_performance(performance): data = MyForm( Field("subTaskId", is_mandatory=True, validators=[ SubTask.check_exists, SubTask.for_task(performance.sub_task.task.task_id), ]), ).get_data() try: performance.move_to(data["subTaskId"], AudioCheckingChangeMethod.ADMIN, session["current_user"].user_id) except SelfTransition: raise InvalidUsage("self transition") except LockedPerformance: raise InvalidUsage("performance is locked") except InvalidTransition: raise InvalidUsage("invalid transition") db.session.flush() return jsonify(performance=Performance.dump(performance))
def move_performances(recording_platform): data = MyForm( Field("changeMethod", is_mandatory=True, validators=[AudioCheckingChangeMethod.is_valid]), Field("subTaskId", is_mandatory=True, validators=[SubTask.check_exists]), Field("rawPieceIds", is_mandatory=True, validators=[ validators.is_list, Performance.check_all_exists, ]), ).get_data() destination = SubTask.query.get(data["subTaskId"]) performances = [] for raw_piece_id in data["rawPieceIds"]: performance = Performance.query.get(raw_piece_id) performances.append(performance) moved, at_destination, no_transition, locked = recording_platform.move_performances( performances, destination, session["current_user"].user_id, data["changeMethod"]) db.session.flush() return jsonify({ "atDestination": len(at_destination), "noTransition": len(no_transition), "moved": len(moved), "locked": len(locked), "performances": Performance.dump(performances, use="full"), })
def load_batch_context(batchId): me = session['current_user'] batch = m.Batch.query.get(batchId) if not batch: raise InvalidUsage(_('batch {0} not found').format(batchId), 404) task = batch.task subTask = batch.subTask # check if current user has the capability to view batch # this allows supervisors to check progress view_only = bool( request.args.get('viewOnly', None) and 'admin' in session['current_user_caps']) if batch.userId != me.userId and not view_only: raise InvalidUsage( _('Sorry, you have requested a batch that you don\'t own. ' 'If you have any questions, please contact your transcription supervisor.' )) permit = m.TaskWorker.query.get( (me.userId, task.taskId, subTask.subTaskId)) if (not permit or permit.removed) and not view_only: # TODO: take back assigned batch if user got removed? raise InvalidUsage(_('Sorry, you are not assigned to this sub task.')) now = datetime.datetime.utcnow().replace(tzinfo=pytz.utc) if batch.leaseExpires and batch.leaseExpires <= now and not view_only: # TODO: take back expired batch raise InvalidUsage( _( 'Sorry, you current work lease is expired.', 'Please select another item to work on.', 'If you have any questions, please contact your transcription supervisor.' ).format()) showGuideline = (subTask.instructionPage != None and subTask.instructionPage.strip() and permit and not permit.hasReadInstructions) batch_context = dict( contextType='batch', task=m.Task.dump(batch.task), subTask=m.SubTask.dump(batch.subTask), batch=m.Batch.dump(batch, use='full'), showGuideline=showGuideline, ) # get audio checking context if task.is_type(TaskType.AUDIO_CHECKING): # expect exactly one performance per batch if len(batch.pages) != 1 or len(batch.pages[0].members) != 1: raise RuntimeError("expected exactly one member") performance = batch.pages[0].members[0].rawPiece batch_context.update({ "audioCheckingGroups": AudioCheckingGroup.dump( performance.recording_platform.audio_checking_groups), "audioCheckingSections": AudioCheckingSection.dump( performance.recording_platform.audio_checking_sections), "metaCategories": PerformanceMetaCategory.dump( performance.recording_platform.performance_meta_categories), "metaValues": PerformanceMetaValue.dump(performance.meta_values), "performance": Performance.dump(performance), "performanceFlags": PerformanceFlag.dump(task.performance_flags), "recordings": Recording.dump(performance.recordings), "recordingFlags": RecordingFlag.dump(task.recording_flags), "recordingPlatform": RecordingPlatform.dump(performance.recording_platform), }) # get other task type context else: tagSet = None if task.tagSetId is None else m.TagSet.query.get( task.tagSetId) labelSet = None if task.labelSetId is None else m.LabelSet.query.get( task.labelSetId) taskErrorTypes = m.TaskErrorType.query.filter_by( taskId=task.taskId).all() batch_context.update( dict( tagSet=m.TagSet.dump(tagSet, use='smart', context={'subTaskId': batch.subTaskId}) if tagSet else None, labelSet=m.LabelSet.dump(labelSet, use='smart', context={ 'subTaskId': batch.subTaskId }) if labelSet else None, taskErrorTypes=m.TaskErrorType.dump(taskErrorTypes), keyExpansions=m.KeyExpansion.dump(task.expansions), )) return jsonify(**batch_context)
def get_album_performances(album): return jsonify({"performances": Performance.dump(album.performances)})