def save(self):
     """ Saves a Customer in the database """
     if self.username is None:
         raise DataValidationError('username is not set')
     if self.password is None:
         raise DataValidationError('password is not set')
     if self.firstname is None:
         raise DataValidationError('firstname is not set')
     if self.lastname is None:
         raise DataValidationError('lastname is not set')
     if self.email is None:
         raise DataValidationError('email is not set')
     if self.id == 0:
         self.id = Customer.__next_index()
     Customer.redis.set(self.id, pickle.dumps(self.serialize()))
Exemple #2
0
    def deserialize(self, data):
        if not isinstance(data, dict):
            raise DataValidationError(
                'Invalid wishlist data: body of request contained bad or no data'
            )

        if data.has_key('Product List'):
            self.product_list = [p for p in data['Product List']]

        try:
            self.wishlist_name = data['name']
        except KeyError as err:
            raise DataValidationError(
                'Invalid wishlist: missing wishlist name')
        return
Exemple #3
0
    def save(self):
        if self.cust_id == 0:
            raise DataValidationError(
                'Invalid customer ID : Please provide a valid ID')
        if Customer.redis.exists(self.cust_id):
            maxi = 0
            message = pickle.loads(Customer.redis.get(self.cust_id))

            for m in message.iteritems():
                if m[0] > maxi:
                    maxi = m[0]

            w = Wishlist()
            i = maxi + 1
            w.save_values(i, self.wishlist_name, self.product_list)
            new_message = w.display_by_id()
            message.update(new_message)
            Customer.redis.set(self.cust_id, pickle.dumps(message))
            message = w.display_by_id()
            return {"Customer ID": self.cust_id, "Wishlist": message}
        else:
            w = Wishlist()
            w.save_values(1, self.wishlist_name, self.product_list)
            message = w.display_by_id()
            Customer.redis.set(self.cust_id, pickle.dumps(message))
            return {"Customer ID": self.cust_id, "Wishlist": message}
 def save(self):
     """ Saves a Promotion in the database """
     if self.productid is None:  # productid is the only required field
         raise DataValidationError('productid attribute is not set')
     if self.id == 0:
         self.id = Promotion.__next_index()
     Promotion.redis.set(self.id, pickle.dumps(self.serialize()))
Exemple #5
0
 def save(self):
     """ Saves a Order in the database """
     if self.name is None:  # name is the only required field
         raise DataValidationError('name attribute is not set')
     if self.id == 0:
         self.id = Order.__next_index()
     Order.redis.set(self.id, pickle.dumps(self.serialize()))
Exemple #6
0
 def deserialize(self, data):
     """ deserializes a Order my marshalling the data """
     if isinstance(data, dict) and Order.__validator.validate(data):
         self.name = data['name']
         self.time = data['time']
         self.status = data['status']
     else:
         raise DataValidationError('Invalid order data: ' +
                                   str(Order.__validator.errors))
     return self
Exemple #7
0
 def deserialize(self, data):
     """ deserializes a Item my marshalling the data """
     if isinstance(data, dict) and Item.__validator.validate(data):
         self.name = data['name']
         self.price = data['price']
         self.available = data['available']
     else:
         raise DataValidationError('Invalid item data: ' +
                                   str(Item.__validator.errors))
     return self
Exemple #8
0
 def deserialize(self, data):
     """ deserializes a Pet my marshalling the data """
     if isinstance(data, dict) and Pet.__validator.validate(data):
         self.name = data['name']
         self.category = data['category']
         self.available = data['available']
     else:
         raise DataValidationError('Invalid pet data: ' +
                                   str(Pet.__validator.errors))
     return self
 def deserialize(self, data):
     """ deserializes a Promotion my marshalling the data """
     if isinstance(data, dict) and Promotion.__validator.validate(data):
         self.productid = data['productid']
         self.category = data['category']
         self.available = data['available']
         self.discount = data['discount']
     else:
         raise DataValidationError('Invalid promotion data: ' +
                                   str(Promotion.__validator.errors))
     return self
    def deserialize(self, data):
        """ Deserializes a Customer by marshalling the data """
        if isinstance(data, dict) and Customer.__validator.validate(data):
            self.username = data['username']
            self.password = data['password']
            self.firstname = data['firstname']
            self.lastname = data['lastname']
            self.address = data['address']
            self.phone = data['phone']
            self.email = data['email']
            self.active = data['active']
            self.promo = data['promo']
        else:
            raise DataValidationError('Invalid customer data: ' +
                                      str(Customer.__validator.errors))

        return self