예제 #1
0
def _get_card_set_data(user_id, collection_name, set_name):
    cards_in_set = list(
        Card.filter({
            'card_set': set_name
        }).order_by('number').run())

    user_hash = {'user_id': user_id}
    if collection_name:
        user_hash['collection_id'] = _get_collection_id(
            user_id, collection_name)

    user_cards_data = list(
        UserCard.filter(r.row['count'] > 0).filter(user_hash).run())

    for card in cards_in_set:
        card['edition_counts'] = {}
        for edition in card['editions']:
            edition_superset = edition['type'].split('-')[0]
            user_card_data = list(
                filter(
                    lambda user_card:
                    (user_card['card_code'], user_card['edition_superset']) ==
                    (card['card_code'], edition_superset), user_cards_data))
            card['edition_counts'][edition_superset] = reduce(
                lambda left, right: {'count': left['count'] + right['count']},
                user_card_data)['count'] if user_card_data else 0

    return {
        'normalized_set_name': _normalized_card_set(set_name),
        'set_name': set_name,
        'cards': cards_in_set,
        'editions':
        _user_set_editions_in_order(_normalized_card_set(set_name)),
        'edition_keys': _set_editions_in_order(_normalized_card_set(set_name)),
        'collection_name': collection_name
    }
예제 #2
0
def refresh_fulltext_search_field():
    cards = Card.filter(r.row.has_fields('fulltext')).run()
    for card in cards:
        fulltext_string = _check(card)
        Card.get(card['id']).update({'fulltext': fulltext_string})