def parse_decklist(self):
     self.cards = None
     if self.decklist.startswith('<?xml'):
         try:
             self.cards = decklist.parse_xml(self.decklist)
         except InvalidDataException as e:
             self.errors['decklist'] = 'Unable to read .dek decklist. Try exporting from Magic Online as Text and pasting the result.'.format(specific=str(e))
     else:
         try:
             self.cards = decklist.parse(self.decklist)
         except InvalidDataException as e:
             self.errors['decklist'] = '{specific}. Try exporting from Magic Online as Text and pasting the result.'.format(specific=str(e))
Esempio n. 2
0
 def do_validation(self):
     if len(self.mtgo_username) == 0:
         self.errors['mtgo_username'] = "******"
     elif active_decks_by(self.mtgo_username.strip()):
         self.errors[
             'mtgo_username'] = "******"
     if len(self.name.strip()) == 0:
         self.errors['name'] = 'Deck Name is required'
     else:
         self.source = 'League'
         self.competition_id = db().value(active_competition_id_query())
         self.identifier = identifier(self)
         self.url = url_for('competitions',
                            competition_id=self.competition_id)
     self.decklist = self.decklist.strip()
     if len(self.decklist) == 0:
         self.errors['decklist'] = 'Decklist is required'
     else:
         self.cards = None
         if self.decklist.startswith('<?xml'):
             try:
                 self.cards = decklist.parse_xml(self.decklist)
             except InvalidDataException as e:
                 self.errors[
                     'decklist'] = 'Unable to read .dek decklist. Try exporting from MTGO as Text and pasting the result.'.format(
                         specific=str(e))
         else:
             try:
                 self.cards = decklist.parse(self.decklist)
             except InvalidDataException as e:
                 self.errors[
                     'decklist'] = '{specific}. Try exporting from MTGO as Text and pasting the result.'.format(
                         specific=str(e))
         if self.cards is not None:
             try:
                 vivified = decklist.vivify(self.cards)
                 errors = {}
                 if 'Penny Dreadful' not in legality.legal_formats(
                         vivified, None, errors):
                     self.errors[
                         'decklist'] = 'Deck is not legal in Penny Dreadful - {error}'.format(
                             error=errors.get('Penny Dreadful'))
             except InvalidDataException as e:
                 self.errors['decklist'] = str(e)