def _preprocess_post_data(self, data): project_id = data["project_id"] info = data["info"] duplicate = task_repo.find_duplicate(project_id=project_id, info=info) if duplicate: message = {'reason': 'DUPLICATE_TASK', 'task_id': duplicate} raise Conflict(json.dumps(message)) if 'n_answers' not in data: project = Project(**get_project_data(project_id)) data['n_answers'] = project.get_default_n_answers() invalid_fields = validate_required_fields(info) if invalid_fields: raise BadRequest('Missing or incorrect required fields: {}'.format( ','.join(invalid_fields)))
def _preprocess_post_data(self, data): project_id = data["project_id"] info = data["info"] duplicate = task_repo.find_duplicate(project_id=project_id, info=info) if duplicate: message = {'reason': 'DUPLICATE_TASK', 'task_id': duplicate} raise Conflict(json.dumps(message)) if 'n_answers' not in data: project = Project(**get_project_data(project_id)) data['n_answers'] = project.get_default_n_answers() invalid_fields = validate_required_fields(info) if invalid_fields: raise BadRequest('Missing or incorrect required fields: {}'.format( ','.join(invalid_fields))) if data.get('gold_answers'): try: gold_answers = data['gold_answers'] if type(gold_answers) is dict: data['calibration'] = 1 data['exported'] = True except Exception as e: raise BadRequest('Invalid gold_answers')