Esempio n. 1
0
 def import_data(self, data):
     """Validates request data from user"""
     try:
         if len(data["title"].strip()) == 0:
             return "Invalid"
         else:
             self.title = data["title"]
             self.message = data["message"]
     except KeyError as e:
         raise ValidationError("Invalid: Field required: " + e.args[0])
     return self
Esempio n. 2
0
 def import_data(self, data):
     """Validates request data from user"""
     try:
         if len(data['name'].strip()) == 0:
             return "Invalid"
         else:
             self.name = data['name']
             self.description = data['description']
             self.location = data['location']
             self.category = data['category']
     except KeyError as e:
         raise ValidationError("Invalid: Field required: " + e.args[0])
     return self
Esempio n. 3
0
 def _validate_note(note: str):
     if note and len(note) > Transaction.NOTE_MAX:
         raise ValidationError(
             f"Note has to be max {Transaction.NOTE_MAX} characters long")
Esempio n. 4
0
 def _validate_transactions(self, transactions: list['Transaction']):
     for t in transactions:
         if t.account != self:
             raise ValidationError(
                 f"Transaction {t} in the list is related to another account <{t.account}>"
             )
Esempio n. 5
0
 def _validate_currency(curr_code: str):
     if not Currency.exists(curr_code):
         raise ValidationError(
             f"The currency {curr_code} is not yet supported")
Esempio n. 6
0
 def _validate_name(name: str):
     if not Account.NAME_MIN <= len(name) <= Account.NAME_MAX:
         raise ValidationError(
             f"Name has to be min {Account.NAME_MIN} and max {Account.NAME_MAX} characters long "
             f"but was <{name}>")
Esempio n. 7
0
 def _validate_type(cat_type: str):
     if not CategoryType.exists(cat_type):
         raise ValidationError(
             f"Wrong category type has been specified <{cat_type}>")