def _get_menu(): menu = memcache.get('doubleb_menu') if not menu: company = DoublebCompany.get() menu = get_doubleb_menu(company)['menu'] category = MenuCategory(id=667) category.category = MenuCategory.get_initial_category().key category.title = u'Напитки' categories = [category] items = [] for index, item_dict in enumerate(menu[u'Напитки']): item = MenuItem(id=int(item_dict['id'])) item.category = category.key item.price = item_dict['price'] * 100 item.title = item_dict['title'] item.picture = '' item.description = '' item.order = index item.kal = 0 item.weight = 0 items.append(item) items, modifiers = _set_modifiers(items) menu = categories, items, modifiers memcache.set('doubleb_menu', menu, time=3600) return menu
def __get_products(category, resto_products): products = [] group_modifiers = {} single_modifiers = {} for resto_product in resto_products: product = MenuItem(id=resto_product['productId']) product.category = category.key product.title = resto_product['name'] product.description = resto_product['description'] product.weight = resto_product['weight'] * 1000 product.kal = int(resto_product['energyAmount'] or 0) product.carbohydrate = float(resto_product['carbohydrateAmount'] or 0) product.fat = float(resto_product['fatAmount'] or 0) product.fiber = float(resto_product['fiberAmount'] or 0) product.picture = resto_product['images'][0] if resto_product[ 'images'] else '' product.price = int(resto_product['price'] * 100) product.sequence_number = resto_product['order'] products.append(product) product_group_modifiers = __get_group_modifiers( resto_product['modifiers']) product.group_modifiers = product_group_modifiers.keys() group_modifiers.update(product_group_modifiers) product_single_modifiers = __get_single_modifiers( resto_product['single_modifiers']) product.single_modifiers = product_single_modifiers.keys() single_modifiers.update(product_single_modifiers) return products, group_modifiers, single_modifiers
def post(self): category_id = self.request.get_range('category_id') category = MenuCategory.get_by_id(category_id) if not category: self.abort(400) item = MenuItem(title=self.request.get('title')) item.description = self.request.get('description') if self.request.get('price'): price = float(self.request.get('price')) item.price = int(round(price * 100)) item.kal = self.request.get_range('kal') if self.request.get('volume'): item.volume = float(self.request.get('volume')) if self.request.get('weight'): item.weight = float(self.request.get('weight')) item.sequence_number = category.generate_sequence_number() item.put() # it is need to get id in saving image if self.request.get('image_file') or self.request.get('picture'): if self.request.get('image_file'): new_url = get_new_image_url('MenuItem', item.key.id(), image_data=str(self.request.get('image_file'))) if new_url: item.picture = new_url elif self.request.get('picture'): new_url = get_new_image_url('MenuItem', item.key.id(), url=self.request.get('picture')) if new_url: item.picture = new_url if item.picture: item.icon = get_new_image_url('MenuItemIcon', item.key.id(), url=item.picture, size=ICON_SIZE) item.category = category.key if not self.request.get('restriction_on'): for venue in Venue.query().fetch(): item.restrictions.append(venue.key) item.put() self.redirect('/company/menu/item/list?category_id=%s' % category_id)
def menu_parse(file_excel): wb = xlrd.open_workbook(file_contents=file_excel) sh = wb.sheet_by_index(0) categories = {} products = {} group_modifiers = {} group_choices = {} for row_number in range(sh.nrows): if row_number > 0: current_category = MenuCategory() current_item = MenuItem() current_modifier = GroupModifier() current_choice = GroupModifierChoice() item_add = True for index, cell in enumerate(sh.row_values(row_number)): if index == 0: current_category.sequence_number = int(cell) current_item.sequence_number = int(cell) elif index == 1: if categories.get(cell): current_category = categories[cell] else: current_category.title = cell categories[cell] = current_category elif index == 2: if products.get(cell): current_item = products[cell] item_add = False else: current_item.title = cell products[cell] = current_item elif index == 3: if item_add: current_item.description = cell elif index == 4 and cell: if item_add: current_item.price = int(float(cell) * 100) elif index == 5: if item_add and cell: current_item.volume = float(cell) elif index == 6: if item_add and cell: current_item.weight = float(cell) elif index == 7: if item_add and cell: current_item.kal = int(cell) elif index == 8: if cell: if group_modifiers.get(cell): current_modifier = group_modifiers[cell] else: current_modifier.title = cell group_modifiers[cell] = current_modifier elif index == 9: if cell: current_choice.title = cell elif index == 10: if cell or cell == 0: current_choice.price = int(float(cell) * 100) key = '%s_%s' % (current_choice.title, current_choice.price) if group_choices.get(key): current_choice = group_choices[key] else: current_choice.choice_id = GroupModifierChoice.generate_id( ) group_choices[key] = current_choice if current_choice not in current_modifier.choices: current_modifier.choices.append(current_choice) current_choice.put() logging.info(current_modifier) if current_modifier.title: current_modifier.put() if current_modifier.key not in current_item.group_modifiers: current_item.group_modifiers.append(current_modifier.key) current_item.put() if item_add: current_item.category = current_category.key current_category.put()