Пример #1
0
 def __init__(self, title, description='', owner=None):
     # test to ensure a user is never None
     if owner:
         if utilities.check_type(owner, User):
             self.owner = owner
     if self.owner:
         if utilities.check_type(title, str):
             self.title = title
         if utilities.check_type(description, str):
             self.description = description
     else:
         raise ValueError('Invalid arguments')
Пример #2
0
 def __init__(self, name, email, password, username):
     if utilities.check_type(
             name, str, error_string="A user's name can only be a string"):
         self.name = name
     if utilities.check_email_format(email):
         self.email = email
     if utilities.check_password_format(password):
         self.password = Bcrypt().generate_password_hash(password).decode()
     if utilities.check_type(
             username,
             str,
             error_string="A user's username can only be a string"):
         self.username = username
Пример #3
0
 def __init__(self,
              name,
              quantity=0,
              unit='',
              parent_list=None):  # , parent_list=None):
     # test that an item is never created parent_list = None
     if parent_list:
         if utilities.check_type(parent_list, GroceryList):
             self.parent_list = parent_list
     if self.parent_list:
         if utilities.check_type(name, str):
             self.name = name
         if utilities.check_type(quantity, float, int):
             self.quantity = float(quantity)
         if utilities.check_type(unit, str):
             self.unit = unit
     else:
         raise ValueError('Invalid arguments')
Пример #4
0
 def set_username(self, username):
     if ' ' in username:
         raise ValueError('Username should have no space')
     if utilities.check_type(
             username,
             str,
             error_string="A user's username can only be a string"):
         self.username = username
         db.session.commit()
Пример #5
0
 def check_blacklist(token):
     """
     Check whether the token exists in the blacklist
     """
     if utilities.check_type(token, str):
         result = BlacklistToken.query.filter_by(token=token).first()
         if result:
             return True
         else:
             return False
Пример #6
0
 def get_grocery_list_by_title(self, title):
     """
     Get the shopping list with the given title
     if it belongs to the user
     """
     shopping_list = None
     if utilities.check_type(title, str):
         shopping_list = GroceryList.query.filter_by(title=title,
                                                     owner=self).first()
     return shopping_list
Пример #7
0
 def __init__(self, token):
     if isinstance(token, bytes):
         # convert the bytes to string
         token = token.decode('utf-8')
     if utilities.check_type(token, str):
         # attempt to decode it
         user_id = User.decode_token(token)
         if not isinstance(user_id, str):
             self.token = token
         else:
             raise ValueError('The token should be valid')
     self.blacklisted_on = datetime.now()
Пример #8
0
 def set_quantity(self, quantity):
     if utilities.check_type(quantity, float, int):
         self.quantity = float(quantity)
         db.session.commit()
Пример #9
0
 def set_unit(self, unit):
     if utilities.check_type(unit, str):
         self.unit = unit
         db.session.commit()
Пример #10
0
 def set_name(self, name):
     if utilities.check_type(name, str):
         self.name = name
         db.session.commit()
Пример #11
0
 def get_grocery_item_by_name(self, name):
     grocery_item = None
     if utilities.check_type(name, str):
         grocery_list = GroceryList.query.filter_by(
             name=name, parent_list=self).first()
     return grocery_item
Пример #12
0
 def add_item(self, item_name):
     if utilities.check_type(item_name, str):
         grocery_item = GroceryItem(item_name, parent_list=self)
         grocery_item.save()
         return GroceryItem.query.filter_by(name=item_name,
                                            parent_list=self).first()
Пример #13
0
 def set_description(self, description):
     if utilities.check_type(description, str):
         self.description = description
         db.session.commit()
Пример #14
0
 def set_title(self, title):
     if utilities.check_type(title, str):
         self.title = title
         db.session.commit()
Пример #15
0
 def set_name(self, name):
     if utilities.check_type(
             name, str, error_string="A user's name can only be a string"):
         self.name = name
         db.session.commit()