def flush_entities(db_conn, descs): """ Given a list of kinds and entity_ids, return a list filled out with entities. """ output = [] for desc in descs: if desc['kind'] == 'card': card = Card.get_latest_accepted(db_conn, entity_id=desc['id']) card = flip_card_into_kind(card) if card: output.append(card) elif desc['kind'] == 'unit': output.append(Unit.get_latest_accepted( db_conn, entity_id=desc['id'] )) elif desc['kind'] == 'set': output.append(Set.get_latest_accepted( db_conn, entity_id=desc['id'] )) else: output.append(None) return output
def flush_entities(db_conn, descs): """ Given a list of kinds and entity_ids, return a list filled out with entities. """ output = [] for desc in descs: if desc['kind'] == 'card': card = Card.get_latest_accepted(db_conn, entity_id=desc['id']) card = flip_card_into_kind(card) if card: output.append(card) elif desc['kind'] == 'unit': output.append(Unit.get_latest_accepted( db_conn, entity_id=desc['id'] )) elif desc['kind'] == 'set': output.append(Set.get_latest_accepted( db_conn, entity_id=desc['id'] )) else: output.append(None) return output
def get_latest_accepted(kind, entity_id): """ Given a kind and an entity_id, pull the latest accepted version out of the database. """ if kind == 'card': return Card.get_latest_accepted(entity_id) # TODO-1 This needs to also get the right card kind... elif kind == 'unit': return Unit.get_latest_accepted(entity_id) elif kind == 'set': return Set.get_latest_accepted(entity_id)
def get_latest_accepted(db_conn, kind, entity_id): """ Given a kind and an entity_id, pull the latest accepted version out of the database. """ if kind == 'card': card = Card.get_latest_accepted(db_conn, entity_id) return flip_card_into_kind(card) elif kind == 'unit': return Unit.get_latest_accepted(db_conn, entity_id) elif kind == 'set': return Set.get_latest_accepted(db_conn, entity_id)
def get_latest_accepted(kind, entity_id): """ Given a kind and an entity_id, pull the latest accepted version out of the database. """ if kind == 'card': return Card.get_latest_accepted(entity_id) # TODO-1 This needs to also get the right card kind... elif kind == 'unit': return Unit.get_latest_accepted(entity_id) elif kind == 'set': return Set.get_latest_accepted(entity_id)
def get_latest_accepted(db_conn, kind, entity_id): """ Given a kind and an entity_id, pull the latest accepted version out of the database. """ if kind == 'card': card = Card.get_latest_accepted(db_conn, entity_id) return flip_card_into_kind(card) elif kind == 'unit': return Unit.get_latest_accepted(db_conn, entity_id) elif kind == 'set': return Set.get_latest_accepted(db_conn, entity_id)
def get_set_units_route(request, set_id): """ Present a small number of units the learner can choose from. NEXT STATE GET Choose Unit -> POST Choose Unit """ db_conn = request['db_conn'] # TODO-3 simplify this method. should it be part of the models? current_user = get_current_user(request) if not current_user: return abort(401) context = get_learning_context(current_user) next_ = { 'method': 'POST', 'path': '/s/sets/{set_id}/units/{unit_id}'.format(set_id=context.get( 'set', {}).get('entity_id'), unit_id='{unit_id}'), } set_learning_context(current_user, next=next_) set_ = Set.get_latest_accepted(db_conn, set_id) # Pull a list of up to 5 units to choose from based on priority. buckets = traverse(db_conn, current_user, set_) units = buckets['learn'][:5] # TODO-3 Time estimates per unit for mastery. return 200, { 'next': next_, 'units': [unit.deliver() for unit in units], # For the menu, it must return the name and ID of the set 'set': set_.deliver(), 'current_unit_id': context.get('unit', {}).get('entity_id'), }
def flush_entities(descs): """ Given a list of kinds and entity_ids, return a list filled out with entities. """ output = [] for desc in descs: if desc['kind'] == 'card': output.append(Card.get_latest_accepted(entity_id=desc['id'])) # TODO-1 This needs to also get the right card kind... elif desc['kind'] == 'unit': output.append(Unit.get_latest_accepted(entity_id=desc['id'])) elif desc['kind'] == 'set': output.append(Set.get_latest_accepted(entity_id=desc['id'])) else: output.append(None) return output
def flush_entities(descs): """ Given a list of kinds and entity_ids, return a list filled out with entities. """ output = [] for desc in descs: if desc['kind'] == 'card': output.append(Card.get_latest_accepted(entity_id=desc['id'])) # TODO-1 This needs to also get the right card kind... elif desc['kind'] == 'unit': output.append(Unit.get_latest_accepted(entity_id=desc['id'])) elif desc['kind'] == 'set': output.append(Set.get_latest_accepted(entity_id=desc['id'])) else: output.append(None) return output
def select_set_route(request, user_id, set_id): """ Select the set to work on. NEXT STATE POST Choose Set (Update Learner Context) -> GET View Set Tree """ current_user = get_current_user(request) if not current_user: return abort(401) set_ = Set.get_latest_accepted(set_id) next_ = { 'method': 'GET', 'path': '/s/sets/{set_id}/tree'.format(set_id=set_id), } current_user.set_learning_context(set=set_.data, next=next_) return 200, {'next': next_}
def get_set_route(request, set_id): """ Get a specific set given an ID. """ set_ = Set.get_latest_accepted(set_id) if not set_: return abort(404) # TODO-2 SPLITUP create new endpoints for these instead topics = Topic.list_by_entity_id(entity_id=set_id) versions = Set.get_versions(entity_id=set_id) units = set_.list_units() return 200, { 'set': set_.deliver(), # 'set_parameters': set_.fetch_parameters(), 'topics': [topic.deliver() for topic in topics], 'versions': [version.deliver() for version in versions], 'units': [unit.deliver() for unit in units], }
def get_set_units_route(request, set_id): """ Present a small number of units the learner can choose from. NEXT STATE GET Choose Unit -> POST Choose Unit """ db_conn = request['db_conn'] # TODO-3 simplify this method. should it be part of the models? current_user = get_current_user(request) if not current_user: return abort(401) context = get_learning_context(current_user) next_ = { 'method': 'POST', 'path': '/s/sets/{set_id}/units/{unit_id}' .format(set_id=context.get('set', {}).get('entity_id'), unit_id='{unit_id}'), } set_learning_context(current_user, next=next_) set_ = Set.get_latest_accepted(db_conn, set_id) # Pull a list of up to 5 units to choose from based on priority. buckets = traverse(db_conn, current_user, set_) units = buckets['learn'][:5] # TODO-3 Time estimates per unit for mastery. return 200, { 'next': next_, 'units': [unit.deliver() for unit in units], # For the menu, it must return the name and ID of the set 'set': set_.deliver(), 'current_unit_id': context.get('unit', {}).get('entity_id'), }
def select_set_route(request, user_id, set_id): """ Select the set to work on. NEXT STATE POST Choose Set (Update Learner Context) -> GET View Set Tree """ current_user = get_current_user(request) if not current_user: return abort(401) set_ = Set.get_latest_accepted(set_id) next_ = { 'method': 'GET', 'path': '/s/sets/{set_id}/tree' .format(set_id=set_id), } current_user.set_learning_context(set=set_.data, next=next_) return 200, {'next': next_}
def test_latest_accepted_set(db_conn, sets_table): """ Expect to get the latest accepted set version. """ sets_table.insert([{ 'id': 'A1', 'entity_id': 'A', 'created': r.time(2004, 11, 3, 'Z'), 'status': 'accepted', }, { 'id': 'B2', 'entity_id': 'A', 'created': r.time(2005, 11, 3, 'Z'), 'status': 'accepted', }, { 'id': 'C3', 'entity_id': 'B', 'created': r.time(2006, 11, 3, 'Z'), 'status': 'accepted', }]).run(db_conn) set_ = Set.get_latest_accepted(db_conn, 'A') assert set_['id'] == 'B2'