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
def prepare_card_urls(self, c: Card) -> None: c.url = self.url_for_card(c) c.img_url = self.url_for_image(c.name)
def prepare_card_urls(c: Card, tournament_only: bool = False) -> None: c.url = url_for_card(c, tournament_only) c.img_url = url_for_image(c.name)