def get(self): item_name = self.request.get('name') item = caching.get_one_item(item_name) first_item = None dates = {} if not item or len(item) == 0: item = None else: first_item = item[0] for i in item: dates[i._id] = i.added_date.strftime('%d-%m-%y %H:%M:%S') logging.error(item) categories = list(caching.get_categories()) subcategories = list(caching.get_subcategories()) item_cart = self.session.get('items') store_list = list(caching.get_stores()) self.render( "item_viewer.html", { 'item_name': item_name, 'items': item, 'item': first_item, 'categories': categories, 'subcategories': subcategories, 'store_list': store_list, 'item_cart': item_cart, 'dates': dates, 'is_home': 1 })
def get_items_from_cart(self): """ Fetches items from sessions cart""" items = self.session.get('items') if not items: return None; item_list = [] for item_name, item_count in items.items(): item_list.append((caching.get_one_item(item_name), item_count)) return item_list
def get_items_from_cart(self): """ Fetches items from sessions cart""" items = self.session.get('items') if not items: return None item_list = [] for item_name, item_count in items.items(): item_list.append((caching.get_one_item(item_name), item_count)) return item_list
def post(self): if self.user_info: data = json.loads(self.request.body) item = data['item'] price = float(data['price']) quantity = int(data['quantity']) last_quantity = int(data['last_quantity']) self.session['items'][item] = quantity * price stores = caching.get_stores() if not self.session.get('store_total'): for store in stores: self.session['store_total'][str(store._id)] = 0 items_list = caching.get_one_item(item) if item not in self.session['quantity']: self.session['quantity'][item] = 0 last_quantity = self.session['quantity'][item] for cur_item in items_list: self.session['store_total'][str( cur_item.store)] += cur_item.price * (quantity - last_quantity) if quantity == 0: del self.session['items'][item] total_sum = 0 for m_item, m_cost in self.session['items'].items(): total_sum += m_cost self.session['quantity'][item] = quantity response = {} response["status"] = 1 response["number"] = total_sum for store in stores: response[str(store._id)] = self.session['store_total'][str( store._id)] self.session['item_count'] = total_sum self.response.out.write(json.dumps(response)) else: self.response.out.write(json.dumps({"status": 0})) logging.error("%s not found" % self.user_info.name)
def get(self): item_name = self.request.get('name') item = caching.get_one_item(item_name) first_item = None dates = {} if not item or len(item) == 0: item = None else: first_item = item[0] for i in item: dates[i._id] = i.added_date.strftime('%d-%m-%y %H:%M:%S') logging.error(item) categories = list(caching.get_categories()) subcategories = list(caching.get_subcategories()) item_cart = self.session.get('items') store_list = list(caching.get_stores()) self.render("item_viewer.html", { 'item_name': item_name, 'items': item, 'item': first_item, 'categories': categories, 'subcategories': subcategories, 'store_list': store_list, 'item_cart': item_cart, 'dates': dates, 'is_home': 1 })