Example #1
0
def get_card_by_kind(card_id):
    """
    Given a card data, return a new card model to replace it by kind.
    """

    card = Card.get_latest_accepted(card_id)
    if not card:
        return

    data, kind = card.data, card.data.get('kind')

    map = {
        'audio': AudioCard,
        'choice': ChoiceCard,
        'embed': EmbedCard,
        'formula': FormulaCard,
        'match': MatchCard,
        'number': NumberCard,
        'page': PageCard,
        'slideshow': SlideshowCard,
        'upload': UploadCard,
        'video': VideoCard,
        'writing': WritingCard,
    }

    if kind in map:
        return map[kind](data)
Example #2
0
def get_card_by_kind(db_conn, card_id):
    """
    Given a card data, return a new card model to replace it by kind.
    """

    card = Card.get_latest_accepted(db_conn, card_id)
    return flip_card_into_kind(card)
Example #3
0
def get_card_by_kind(card_id):
    """
    Given a card data, return a new card model to replace it by kind.
    """

    card = Card.get_latest_accepted(card_id)
    if not card:
        return

    data, kind = card.data, card.data.get('kind')

    map = {
        'audio': AudioCard,
        'choice': ChoiceCard,
        'embed': EmbedCard,
        'formula': FormulaCard,
        'match': MatchCard,
        'number': NumberCard,
        'page': PageCard,
        'slideshow': SlideshowCard,
        'upload': UploadCard,
        'video': VideoCard,
        'writing': WritingCard,
    }

    if kind in map:
        return map[kind](data)
Example #4
0
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'] == 'subject':
            output.append(Subject.get_latest_accepted(
                db_conn,
                entity_id=desc['id']
            ))
        else:
            output.append(None)

    return output
Example #5
0
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
Example #6
0
def get_card_by_kind(db_conn, card_id):
    """
    Given a card data, return a new card model to replace it by kind.
    """

    card = Card.get_latest_accepted(db_conn, card_id)
    return flip_card_into_kind(card)
Example #7
0
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)
Example #8
0
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)
Example #9
0
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)
Example #10
0
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)
Example #11
0
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
Example #12
0
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 test_latest_accepted_card(db_conn, cards_table):
    """
    Expect to get the latest accepted card version.
    """

    cards_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)

    card = Card.get_latest_accepted(db_conn, 'A')
    assert card['id'] == 'B2'
Example #14
0
def test_latest_accepted_card(db_conn, cards_table):
    """
    Expect to get the latest accepted card version.
    """

    cards_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)

    card = Card.get_latest_accepted(db_conn, 'A')
    assert card['id'] == 'B2'