def custom_check_card(self, card):
validations = []
#check foreing codes
for collection in ["affiliation", "faction", "rarity", "type", "subtype"]:
field = collection + "_code"
if field in card and not card.get(field) in self.collections[collection]:
validations.append("%s code '%s' does not exists in card '%s'" % (collection, card.get(field), card.get('code')))
#check reprint of
if 'reprint_of' in card and not card.get('reprint_of') in self.collections['card']:
validations.append("Reprinted card %s does not exists" % (card.get('reprint_of')))
#checks by type
check_by_type_method = "custom_check_%s_card" % card.get('type_code')
if hasattr(self, check_by_type_method) and callable(getattr(self, check_by_type_method)):
validations.extend(getattr(self, check_by_type_method)(card))
if validations:
raise jsonschema.ValidationError("\n".join(["- %s" % v for v in validations]))
评论列表
文章目录