Example #1
0
 def __init__(self, d):
     self._deck = d
     self.prepare_deck(self._deck)
     self.cards = d.all_cards()
     # 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 = deck.get_similar_decks(d)
     self.has_similar = len(self.decks) > 0
     self.matches = deck.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('decks',
                                           deck_id=m.opponent_deck_id)
         else:
             m.opponent_deck_url = False
         if m.opponent_deck:
             m.opponent_deck_name = deck_name.normalize(m.opponent_deck)
         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.admin = session.get('admin', False)
     if self.admin:
         self.archetypes = archetype.load_archetypes_deckless(
             order_by='a.name')
         self.edit_archetype_url = url_for('edit_archetypes')
     self.cardhoarder_url = fetcher.cardhoarder_url(d)
Example #2
0
def test_deck_sort_x_last() -> None:
    cards = oracle.load_cards(
        ['Ghitu Fire', 'Flash of Insight', 'Frantic Search'])
    assert len(cards) == 3
    cards_by_name = {c.name: c for c in cards}
    assert oracle.deck_sort(cards_by_name['Ghitu Fire']) < oracle.deck_sort(
        cards_by_name['Flash of Insight'])
    assert oracle.deck_sort(cards_by_name['Ghitu Fire']) > oracle.deck_sort(
        cards_by_name['Frantic Search'])
def test_deck_sort_x_last():
    cards = oracle.load_cards(
        ['Ghitu Fire', 'Flash of Insight', 'Frantic Search'])
    assert len(cards) == 3
    cards = {c.name: c for c in cards}
    assert oracle.deck_sort(cards.get('Ghitu Fire')) < oracle.deck_sort(
        cards.get('Flash of Insight'))
    assert oracle.deck_sort(cards.get('Ghitu Fire')) > oracle.deck_sort(
        cards.get('Frantic Search'))
Example #4
0
 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
Example #5
0
 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
Example #6
0
 def sort(self):
     if not self.sorted and (len(self.maindeck) > 0
                             or len(self.sideboard) > 0):
         self.maindeck.sort(key=lambda x: oracle.deck_sort(x.card))
         self.sideboard.sort(key=lambda x: oracle.deck_sort(x.card))
         self.sorted = True