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. """ card = get_card_by_kind(card_id) if not card: return abort(404) unit = Unit.get_latest_accepted(entity_id=card['unit_id']) if not unit: return abort(404) # TODO-2 SPLITUP create new endpoints for these instead topics = Topic.list_by_entity_id(entity_id=card_id) versions = Card.get_versions(entity_id=card_id) requires = Card.list_requires(entity_id=card_id) required_by = Card.list_required_by(entity_id=card_id) params = CardParameters.get(entity_id=card_id) return 200, { 'card': card.deliver(access='view'), 'card_parameters': params.get_values(), 'unit': unit.deliver(), 'topics': [topic.deliver() for topic in topics], 'versions': [version.deliver() for version in versions], 'requires': [require.deliver() for require in requires], 'required_by': [require.deliver() for require in required_by], }
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_card_by_kind(db_conn, card_id) if not card: return abort(404) unit = Unit.get_latest_accepted(db_conn, entity_id=card['unit_id']) if not unit: return abort(404) # TODO-2 SPLITUP create new endpoints for these instead topics = list_topics_by_entity_id(card_id, {}, db_conn) versions = Card.get_versions(db_conn, entity_id=card_id) requires = Card.list_requires(db_conn, entity_id=card_id) required_by = Card.list_required_by(db_conn, entity_id=card_id) params = get_card_parameters({'entity_id': card_id}, db_conn) return 200, { 'card': card.deliver(access='view'), 'card_parameters': (get_card_parameters_values(params) if params else None), 'unit': unit.deliver(), 'topics': [deliver_topic(topic) for topic in topics], 'versions': [version.deliver() for version in versions], 'requires': [require.deliver() for require in requires], 'required_by': [require.deliver() for require in required_by], }
def test_list_requires(db_conn, cards_table): """ Expect to list all the prereqs for the entity. """ cards_table.insert([{ 'entity_id': 'abcd', 'unit_id': 'zytx', 'created': r.now(), 'modified': r.now(), 'status': 'accepted', 'kind': 'video', 'requires': ['zxyz'], }, { 'entity_id': 'abcd', 'unit_id': 'zytx', 'created': r.time(1986, 11, 3, 'Z'), 'modified': r.time(1986, 11, 3, 'Z'), 'status': 'accepted', 'kind': 'video', }, { 'entity_id': 'zxyz', 'unit_id': 'zytx', 'created': r.now(), 'modified': r.now(), 'status': 'accepted', 'kind': 'video', }, { 'entity_id': 'qwer', 'unit_id': 'zytx', 'created': r.now(), 'modified': r.now(), 'status': 'accepted', 'kind': 'choice', 'requires': ['abcd'], }]).run(db_conn) cards = Card.list_requires(db_conn, 'abcd') assert len(cards) == 1 assert cards[0]['entity_id'] == 'zxyz'