def get_card_route(request, card_id): """ Get a specific card given an ID. Show all relevant data, but not used for the learning interface. """ db_conn = request['db_conn'] card = get_latest_accepted_card(db_conn, card_id) if not card: return abort(404, 'fPebfwqfRNmOiSWqWISeaA') unit = get_latest_accepted_unit(db_conn, card['unit_id']) if not unit: return abort(404, 'IKSqfvHvRK6hbSAIOkQuLg') # TODO-2 SPLITUP create new endpoints for these instead requires = list_required_cards(db_conn, card_id) required_by = list_required_by_cards(db_conn, card_id) params = get_card_parameters(db_conn, {'entity_id': card_id}) return 200, { 'card': deliver_card(card, access='view'), 'card_parameters': (get_card_parameters_values(params) if params else None), 'unit': deliver_unit(unit), 'requires': [deliver_card(require) for require in requires], 'required_by': [deliver_card(require) for require in required_by], }
def choose_unit_route(request, subject_id, unit_id): """ Updates the learner's information based on the unit they have chosen. NEXT STATE POST Chosen Unit -> GET Learn Card """ # TODO-3 simplify this method. should it be broken up or moved to model? db_conn = request['db_conn'] current_user = get_current_user(request) if not current_user: return abort(401, 'NcrRkqIlSW-BkcWLBkwORQ') unit = get_latest_accepted_unit(db_conn, unit_id) if not unit: return abort(404, 'PIti_qwAQ7WXwQwNZertxw') # If the unit isn't in the subject... context = get_learning_context(current_user) subject_ids = [ convert_uuid_to_slug(subject['entity_id']) for subject in list_subjects_by_unit_recursive(db_conn, unit_id) ] context_subject_id = context.get('subject', {}).get('entity_id') if context_subject_id not in subject_ids: return 400, { 'errors': [{ 'message': 'Unit not in subject.', 'ref': 'r32fH0eCRZCivJoh-hKwZQ', }] } # Or, the unit doesn't need to be learned... status = judge(db_conn, unit, current_user) if status == "done": return 400, { 'errors': [{ 'message': 'Unit not needed.', 'ref': 'YTU27E63Rfiy3Rqmqd6Bew', }] } # Choose a card for the learner to learn card = choose_card(db_conn, current_user, unit) if card: next_ = { 'method': 'GET', 'path': '/s/cards/{card_id}/learn'.format( card_id=convert_uuid_to_slug(card['entity_id'])), } else: next_ = {} set_learning_context(current_user, unit=unit, card=card if card else None, next=next_) return 200, {'next': next_}
def test_judge_done(db_conn, session): """ Expect to show "done". """ add_test_subject(db_conn) unit = get_latest_accepted_unit(db_conn, entity_id=unit_add_uuid) user = get_user(db_conn, {'id': user_id}) assert judge(db_conn, unit, user) == "done"
def test_judge_learn(db_conn, session): """ Expect to add known low ability to "learn". """ add_test_subject(db_conn) unit = get_latest_accepted_unit(db_conn, entity_id=unit_multiply_uuid) user = get_user(db_conn, {'id': user_id}) assert judge(db_conn, unit, user) == "learn"
def test_judge_review(db_conn, session): """ Expect to add older, high ability to "review". """ add_test_subject(db_conn) unit = get_latest_accepted_unit(db_conn, entity_id=unit_subtract_uuid) user = get_user(db_conn, {'id': user_id}) assert judge(db_conn, unit, user) == "review"
def test_judge_diagnose(db_conn, session): """ Expect to add no known ability to "diagnose". """ add_test_subject(db_conn) unit = get_latest_accepted_unit(db_conn, entity_id=unit_divide_uuid) user = get_user(db_conn, {'id': user_id}) assert judge(db_conn, unit, user) == "diagnose"
def get_unit_route(request, unit_id): """ Get a specific unit given an ID. """ db_conn = request['db_conn'] unit = get_latest_accepted_unit(db_conn, unit_id) if not unit: return abort(404, '3UyybCLYQwW_kHO1AumIuA') # TODO-2 SPLITUP create new endpoints for these instead requires = list_required_units(db_conn, unit_id) required_by = list_required_by_units(db_conn, unit_id) subjects = list_subjects_by_unit_flat(db_conn, unit_id) return 200, { 'unit': deliver_unit(unit), # TODO-3 unit parameters 'requires': [deliver_unit(require) for require in requires], 'required_by': [deliver_unit(require) for require in required_by], 'belongs_to': [deliver_subject(subject) for subject in subjects], }
def create_existing_unit_version_route(request, unit_id): """ Create a new unit version for an existing unit. """ current_user = get_current_user(request) if not current_user: return abort(401, 'Xfy4fdwwSnuRCiTci-leYQ') db_conn = request['db_conn'] next_data = deepcopy(request['params']) next_data['entity_id'] = unit_id next_data['user_id'] = current_user['id'] current_data = get_latest_accepted_unit(db_conn, unit_id) if not current_data: return abort(404, 'SDJ6WP_gRe28hmsTEKejsg') unit, errors = insert_unit_version(db_conn, current_data, next_data) if errors: return 400, { 'errors': errors, 'ref': 'Oy9dmO9BRiSciigcbeiqrQ', } return 200, {'version': deliver_unit(unit, 'view')}
def test_get_latest_accepted_unit(db_conn): create_unit_test_data(db_conn) unit = get_latest_accepted_unit(db_conn, entity_id=unit_a_uuid) assert unit assert unit['status'] == 'accepted' assert unit['entity_id'] == unit_a_uuid