Esempio n. 1
0
	def addProduct(self, list_id, product_name,product_quantity,product_units):
		products = ListOfProducts.getAllProductsIDs(list_id)
		if len(products)!=0:
			for product_id in products:
				product = Product.getProductByID(product_id)
				if product is None:
					Product.addProduct(product_name,product_quantity,product_units, list_id)
					return True
				else:
					return False
		else:
			Product.addProduct(product_name,product_quantity,product_units, list_id)
			return True
Esempio n. 2
0
    def get(self):
        template_params = {}
        user = None
        if self.request.cookies.get('session'):
            user = User.checkToken(self.request.cookies.get('session'))
        if not user:
            self.redirect('/')
            return
        #show the all the products of the list

        list_id = int(self.request.cookies.get('list_id_cookie'))
        if list_id:
            pid = self.request.get('pid')
            if pid:
                List.deleteProductFromList(list_id, int(pid))
                p_name = self.request.get('p_name')
                p_quantity = self.request.get('p_quantity')
                p_units = self.request.get('p_units')
                if p_name and p_quantity and p_units:
                    if Product.checkIfProductExists(p_name, list_id):
                        self.response.write(json.dumps({'status': 'exists'}))
                        return
                    Product.addProduct(p_name, p_quantity, p_units, list_id)
                    time.sleep(0.5)
            new_Product_name = self.request.get('new_Product_name')
            new_Product_quantity = self.request.get('new_Product_quantity')
            new_Product_units = self.request.get('new_Product_units')
            if new_Product_name and new_Product_quantity and new_Product_units:
                if Product.checkIfProductExists(new_Product_name, list_id):
                    self.response.write(json.dumps({'status': 'exists'}))
                    return
                Product.addProduct(new_Product_name, new_Product_quantity,
                                   new_Product_units, list_id)
                time.sleep(0.5)
            listProducts = List.getAllProductsOfTheList(list_id)
            list_name = List.getListByID(list_id).ListName
            user_permit = List.getUserPermit(list_id, user.email)
            data = []
            if list_name:
                data.append(list_name)
                data.append(listProducts)
                data.append(user_permit)
                self.response.write(json.dumps(data))
        else:
            self.response.write(json.dumps({'status': 'error'}))