def getAllProducts(category, brand): product_list = [] brand_products = mongoProductmaster.find({'category':category, 'brand':brand}) prodList = {} for prod in brand_products: prodList[prod['product_name']] = prod['product_id'] return prodList
def getAllProduct_name(category, brand): product_list = [] brand_products = mongoProductmaster.find({ 'category': category, 'brand': brand }) product_list = [prod['product_name'] for prod in brand_products] return product_list
def getProductAutoCompleteList(category, qu): if category is not "all": allProducts = mongoProductmaster.find({'category': category}) else: allProducts = mongoProductmaster.find() productList = [] for products in allProducts: producDict = {} if qu.lower() in products['product_name'].lower(): producDict['name'] = products['product_name'] producDict['type'] = products['category'] producDict[ 'icon'] = "https://s3-ap-southeast-1.amazonaws.com/bazaarfunda/Website/static/ProductImage/" + products[ 'product_id'] + ".jpg" productList.append(producDict) return productList
def getAllProducts(): try: category = getArgAsList(request, 'category')[0] except: category = None if category: allProducts = mongoProductmaster.find({"category": category}) else: allProducts = mongoProductmaster.find() csvStrings = [] csvList = [] for product in allProducts: product_id = product['product_id'] priceDict, min_priceDict = getProductPrice(product_id) category = product['category'] brand = product['brand'] try: lowestprice = str(min_priceDict['price']) except: lowestprice = "" keywordsRating = getProductRating(product_id) rating = 0.0 sumC = 0 for keyword in keywordsRating: rating = rating + float(keyword['rating']) sumC = sumC + 1 if sumC != 0: rating = rating / sumC rating = str(rating) rowList = [product_id, brand, lowestprice, category, rating] csvList.append(rowList) for csvLine in csvList: csvStrings += [",".join(csvLine)] csvStrings = "\n".join(csvStrings) response = make_response(csvStrings) # This is the key: Set the right header for the response # to be downloaded, instead of just printed on the browser response.headers[ "Content-Disposition"] = "attachment; filename=" + category + "_allProducts.csv" return response
def getAllProducts(): try: category = getArgAsList(request, 'category')[0] except: category = None if category: allProducts = mongoProductmaster.find({"category":category}) else: allProducts = mongoProductmaster.find() csvStrings= [] csvList = [] for product in allProducts: product_id = product['product_id'] priceDict, min_priceDict = getProductPrice(product_id) category = product['category'] brand = product['brand'] try: lowestprice = str(min_priceDict['price']) except: lowestprice = "" keywordsRating = getProductRating(product_id) rating = 0.0 sumC = 0 for keyword in keywordsRating: rating = rating + float(keyword['rating']) sumC = sumC + 1 if sumC != 0: rating = rating/sumC rating = str(rating) rowList = [product_id, brand, lowestprice, category, rating] csvList.append(rowList) for csvLine in csvList: csvStrings += [",".join(csvLine)] csvStrings = "\n".join(csvStrings) response = make_response(csvStrings) # This is the key: Set the right header for the response # to be downloaded, instead of just printed on the browser response.headers["Content-Disposition"] = "attachment; filename=" + category + "_allProducts.csv" return response
def getAllProducts(category, brand): product_list = [] brand_products = mongoProductmaster.find({ 'category': category, 'brand': brand }) prodList = {} for prod in brand_products: prodList[prod['product_name']] = prod['product_id'] return prodList
def getAllBrands(category): category_products = mongoProductmaster.find({'category': category}) brand_list = [prod['brand'] for prod in category_products] brand_list = list(set(brand_list)) return brand_list
def getAllProduct_name(category, brand): product_list = [] brand_products = mongoProductmaster.find({'category':category, 'brand':brand}) product_list = [prod['product_name'] for prod in brand_products] return product_list
def getAllBrands(category): category_products = mongoProductmaster.find({'category':category}) brand_list = [prod['brand'] for prod in category_products] brand_list = list(set(brand_list)) return brand_list