def __init__(self, d: deck.Deck, person_id: Optional[int] = None, discord_id: Optional[int] = None) -> None: super().__init__() self.deck = d self.prepare_deck(self.deck) self.cards = d.all_cards() if not self.deck.is_in_current_run(): deck.load_similar_decks([d]) # This is called 'decks' and not something more sane because of limitations of Mustache and our desire to use a partial for decktable. self.decks = [ sd for sd in d.similar_decks if not sd.is_in_current_run() ] else: self.decks = [] self.has_similar = len(self.decks) > 0 self.matches = match.get_matches(d, True) for m in self.matches: m.display_date = dtutil.display_date(m.date) if m.opponent: m.opponent_url = url_for('person', person_id=m.opponent) else: m.opponent = 'BYE' m.opponent_url = False if m.opponent_deck_id: m.opponent_deck_url = url_for('deck', deck_id=m.opponent_deck_id) else: m.opponent_deck_url = False if m.opponent_deck and m.opponent_deck.is_in_current_run(): m.opponent_deck_name = '(Active League Run)' elif m.opponent_deck: m.opponent_deck_name = m.opponent_deck.name else: m.opponent_deck_name = '-' if self.has_rounds(): m.display_round = display_round(m) self.deck['maindeck'].sort(key=lambda x: oracle.deck_sort(x['card'])) self.deck['sideboard'].sort(key=lambda x: oracle.deck_sort(x['card'])) self.archetypes = archetype.load_archetypes_deckless(order_by='a.name') self.edit_archetype_url = url_for('edit_archetypes') self.legal_formats = list( sorted(d.legal_formats, key=legality.order_score)) self.is_in_current_run = d.is_in_current_run() self.person_id = person_id self.discord_id = discord_id
def __init__(self, d: deck.Deck, person_id: Optional[int] = None, discord_id: Optional[int] = None) -> None: super().__init__() self.deck = d prepare.prepare_deck(self.deck) self.cards = d.all_cards() self.matches = match.load_matches_by_deck(d, should_load_decks=True) for m in self.matches: m.display_date = dtutil.display_date(m.date) if m.opponent: m.opponent_url = url_for('.person', mtgo_username=m.opponent) else: m.opponent = 'BYE' m.opponent_url = False if m.opponent_deck_id: m.opponent_deck_url = url_for('deck', deck_id=m.opponent_deck_id) else: m.opponent_deck_url = False if m.opponent_deck and m.opponent_deck.is_in_current_run(): m.opponent_deck_name = '(Active League Run)' elif m.opponent_deck: m.opponent_deck_name = m.opponent_deck.name else: m.opponent_deck_name = '-' if self.has_rounds(): m.display_round = display_round(m) self.deck['maindeck'].sort(key=lambda x: oracle.deck_sort(x.card)) self.deck['sideboard'].sort(key=lambda x: oracle.deck_sort(x.card)) self.archetypes = archetype.load_archetypes_deckless(order_by='a.name') self.edit_archetype_url = url_for('edit_archetypes') self.legal_formats = d.legal_formats self.is_in_current_run = d.is_in_current_run() self.person_id = person_id self.discord_id = discord_id self.is_deck_page = True
def vivify(decklist): validated, invalid_names = {'maindeck': {}, 'sideboard': {}}, set() for section in ['maindeck', 'sideboard']: for name, n in decklist[section].items(): try: validated[section][oracle.valid_name(name)] = n except InvalidDataException: invalid_names.add(name) if invalid_names: raise InvalidDataException('Invalid cards: {invalid_names}'.format(invalid_names='; '.join(invalid_names))) validated_names = list(validated['maindeck'].keys()) + list(validated['sideboard'].keys()) cards = {c.name: c for c in oracle.load_cards(validated_names)} d = Deck({'maindeck': [], 'sideboard': []}) for section in ['maindeck', 'sideboard']: for name, n in validated[section].items(): d[section].append({'n': n, 'name': name, 'card': cards[name]}) return d