def create_pool(): data = MyForm( Field('name', is_mandatory=True, validators=[ validators.non_blank, (check_pool_name_uniqueness, (None, )), ]), Field('meta', is_mandatory=True, default='{}', normalizer=normalize_pool_meta_data), Field('taskTypeId', is_mandatory=True, validators=[ validators.is_number, check_task_type_existence, ]), Field('autoScoring', is_mandatory=True, normalizer=normalize_bool_literal, validators=[ validators.is_bool, ]), Field('tagSetId', validators=[ check_tag_set_existence, ]), Field('dataFile', is_mandatory=True), Field('questions', is_mandatory=True, default=[], normalizer=load_questions), ).get_data(is_json=False) questions = data.pop('questions') del data['dataFile'] pool = m.Pool(**data) SS.add(pool) for qd in questions: q = m.Question(**qd) pool.questions.append(q) SS.flush() return jsonify({ 'pool': m.Pool.dump(pool, context={'level': 0}), })
def submit_marking(sheetId): sheet = m.Sheet.query.get(sheetId) if not sheet: raise InvalidUsage(_('sheet {0} not found').format(sheetId), 404) # TODO: add policy check to enable/disable re-marking and/or marking of expired sheets data = MyForm( Field('moreAttempts', is_mandatory=True, validators=[ validators.is_bool, ]), Field('comment', validators=[ validators.is_string, ]), Field('markings', is_mandatory=True, normalizer=normalize_marking_data), Field('score', is_mandatory=True, default=0, normalizer=calculate_sheet_score), ).get_data() # TODO: define relationship marking on SheetEntry me = session['current_user'] markings = data.pop('markings') for entry, md in zip(sheet.entries, markings): marking = m.Marking(**md) marking.sheetEntryId = entry.sheetEntryId marking.scorerId = me.userId SS.add(marking) SS.flush() entry.markingId = marking.markingId for key in ['moreAttempts', 'comment', 'score']: setattr(sheet, key, data[key]) return jsonify({ 'message': _('marked sheet {0} successfully').format(sheetId), 'sheet': m.Sheet.dump(sheet), })