Пример #1
0
    def prepare_card(self, c: Card) -> None:
        try:
            tournament_only = self.tournament_only #type: ignore
            # mypy complains we haven't declared tournament_only, but that's fine since we're
            # catching the error if it isn't defined by a subclass
        except AttributeError:
            tournament_only = False

        if tournament_only:
            c.url = url_for('.card_tournament', name=c.name)
        else:
            c.url = url_for('.card', name=c.name)

        c.img_url = url_for('image', c=c.name)
        c.card_img_class = 'two-faces' if c.layout in ['transform', 'meld'] else ''
        c.pd_legal = c.legalities.get('Penny Dreadful', False) and c.legalities['Penny Dreadful'] != 'Banned'
        c.legal_formats = {k for k, v in c.legalities.items() if v != 'Banned'}
        c.has_legal_format = len(c.legal_formats) > 0
        if c.get('num_decks') is not None:
            c.show_record = c.get('wins') or c.get('losses') or c.get('draws')
        c.has_decks = len(c.get('decks', [])) > 0
        counter = Counter() # type: ignore
        for d in c.get('decks', []):
            for c2 in d.maindeck:
                if not c2.card.type_line.startswith('Basic Land') and not c2['name'] == c.name:
                    counter[c2['name']] += c2['n']
        most_common_cards = counter.most_common(NUM_MOST_COMMON_CARDS_TO_LIST)
        c.most_common_cards = []
        cs = oracle.cards_by_name()
        for v in most_common_cards:
            self.prepare_card(cs[v[0]])
            c.most_common_cards.append(cs[v[0]])
        c.has_most_common_cards = len(c.most_common_cards) > 0
Пример #2
0
    def prepare_card(self, c: Card) -> None:
        self.prepare_card_urls(c)
        c.card_img_class = 'two-faces' if c.layout in ['transform', 'meld'
                                                       ] else ''
        c.pd_legal = c.legalities.get(
            'Penny Dreadful',
            False) and c.legalities['Penny Dreadful'] != 'Banned'
        c.legal_formats = {k for k, v in c.legalities.items() if v != 'Banned'}
        c.non_pd_legal_formats = {
            k
            for k, v in c.legalities.items()
            if 'Penny Dreadful' not in k and v != 'Banned'
        }
        c.has_legal_format = len(c.legal_formats) > 0
        prepare.set_legal_icons(c)
        if c.get('num_decks') is not None:
            c.show_record = c.get('wins') or c.get('losses') or c.get('draws')

        c.has_decks = len(c.get('decks', [])) > 0
        if not c.has_decks:
            c.has_most_common_cards = False
            return

        counter = Counter()  # type: ignore
        for d in c.get('decks', []):
            for c2 in d.maindeck:
                if not c2.card.type_line.startswith(
                        'Basic Land') and not c2['name'] == c.name:
                    counter[c2['name']] += c2['n']
        most_common_cards = counter.most_common(NUM_MOST_COMMON_CARDS_TO_LIST)
        c.most_common_cards = []
        cs = oracle.cards_by_name()
        for v in most_common_cards:
            self.prepare_card(cs[v[0]])
            c.most_common_cards.append(cs[v[0]])
        c.has_most_common_cards = len(c.most_common_cards) > 0