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(self): venue_id = self.request.get_range('venue_id') if venue_id: venue = Venue.get_by_id(venue_id) else: venue = None category_id = self.request.get_range('category_id') if category_id: category = MenuCategory.get_by_id(category_id) else: category = MenuCategory.get_initial_category() categories = sorted(category.get_categories(venue), key=lambda category: category.sequence_number) self.render('/menu/categories.html', categories=categories, main_category=category, venues=Venue.query().fetch(), chosen_venue=venue)
def post(self): category_id = self.request.get_range('category_id') category = MenuCategory.get_by_id(category_id) if not category: self.abort(400) category.key.delete() self.redirect_to('mt_category_list')
def post(self): logging.info(self.request.POST) category_id = self.request.get_range('category_id') if category_id: category = MenuCategory.get_by_id(category_id) else: category = MenuCategory.get_initial_category() if not category: self.abort(400) for subcategory in category.get_categories(): subcategory.status = bool(self.request.get(str(subcategory.key.id()))) subcategory.put() self.redirect('/company/menu/category/list?%s' % self.request.query_string)
def get(self): categories = MenuCategory.query().fetch() for category in categories: category.items = [] for item in category.get_items(): category.items.append(item) self.render('/promos/gift_add.html', categories=categories)
def get(self): modifier_type = self.request.get_range('modifier_type') modifier = None if modifier_type == SINGLE_MODIFIER: modifier = SingleModifier.get_by_id(self.request.get_range('modifier_id')) elif modifier_type == GROUP_MODIFIER: modifier = GroupModifier.get_by_id(self.request.get_range('modifier_id')) else: self.abort(400) categories = MenuCategory.query().fetch() for category in categories: category.products = [] for product in category.get_items(only_available=True): category.products.append(product) if modifier_type == SINGLE_MODIFIER: if modifier.key in product.single_modifiers: product.has_modifier = True else: product.has_modifier = False elif modifier_type == GROUP_MODIFIER: if modifier.key in product.group_modifiers: product.has_modifier = True else: product.has_modifier = False self.render('/menu/select_products_modifier.html', **{ 'categories': categories, 'modifier': modifier, 'modifier_type': modifier_type })
def get(self): category_id = self.request.get_range('category_id') category = MenuCategory.get_by_id(category_id) if not category: self.abort(400) product_id = self.request.get_range('item_id') product = MenuItem.get_by_id(product_id) if not product: self.abort(400) self.render('/menu/add_item.html', product=product, category=category)
def post(self): logging.info(self.request.POST) category_id = self.request.get_range('category_id') category = MenuCategory.get_by_id(category_id) if not category: self.abort(400) for item in category.get_items(): item.status = bool(self.request.get(str(item.key.id()))) item.put() self.redirect('/company/menu/item/list?category_id=%s' % category_id)
def include_hit_category(menu_dict): if config.HIT_MODULE and config.HIT_MODULE.status == STATUS_AVAILABLE: module = config.HIT_MODULE category_dict = MenuCategory( id='hit_category', title=module.title, picture=module.picture, sequence_number=HIT_SEQUENCE_NUMBER).dict() category_dict['items'] = [item.dict() for item in module.get_items()] if category_dict['items']: menu_dict.append(category_dict)
def _get_category_ids(current_id): q = Queue() q.put(current_id) cats = [] while not q.empty(): current_id = q.get() cats.append(current_id) for category in MenuCategory.query( MenuCategory.category == ndb.Key(MenuCategory, current_id)): q.put(category.key.id()) return cats
def __get_categories(parent_category, resto_categories): categories = {} products = {} group_modifiers = {} single_modifiers = {} for resto_category in resto_categories: category = MenuCategory(id=resto_category['id']) category.category = parent_category.key category.title = resto_category['name'] category.picture = resto_category['image'][0][ 'imageUrl'] if resto_category['image'] else '' category.sequence_number = resto_category['order'] if resto_category['children']: child_categories, child_products, child_group_modifiers, child_single_modifiers, _ = \ __get_categories(category, resto_category['children']) categories.update(child_categories) products.update(child_products) group_modifiers.update(child_group_modifiers) single_modifiers.update(child_single_modifiers) if resto_category['products']: category_products, product_group_modifiers, product_single_modifiers = \ __get_products(category, resto_category['products']) products[category.key] = category_products group_modifiers.update(product_group_modifiers) single_modifiers.update(product_single_modifiers) categories[category.key.id()] = category categories_by_parent = {} for category in categories.itervalues(): categories_by_parent.setdefault(category.category.id(), []).append(category.key.id()) return categories, products, group_modifiers, single_modifiers, categories_by_parent
def get(self): venue_id = self.request.get_range('venue_id') if venue_id: venue = Venue.get_by_id(venue_id) else: venue = None category_id = self.request.get_range('category_id') category = MenuCategory.get_by_id(category_id) if not category: self.abort(400) items = category.get_items_in_order(venue) self.render('/menu/items.html', items=items, category=category, venues=Venue.query().fetch(), chosen_venue=venue)
def _get_menu(force_reload=False): ns = namespace_manager.get_namespace() menu = _global_resto_menu_cache.get(ns) if not menu or force_reload: logging.debug("Not found in instance cache, trying memcache") menu = PickleStorage.get("resto_menu") if not force_reload else None if not menu: logging.debug("Not found in PickleStorage, reloading from resto") resto_company = RestoCompany.get() resto_menu = get_resto_menu(resto_company) init_category = MenuCategory.get_initial_category() menu = __get_categories(init_category, resto_menu['menu']) PickleStorage.save("resto_menu", menu) _global_resto_menu_cache[ns] = menu return menu
def post(self): category_id = self.request.get_range('category_id') category = MenuCategory.get_by_id(category_id) if not category: self.abort(400) next_ = category.get_next_category() if not next_: self.abort(400) _swap_sequence_numbers(category, next_) category.put() next_.put() self.response.headers["Content-Type"] = "application/json" self.response.write(json.dumps({ 'success': True, 'category_id': category.key.id(), 'next_id': next_.key.id() }, separators=(',', ':')))
def post(self): category_id = self.request.get_range('category_id') category = MenuCategory.get_by_id(category_id) if not category: self.abort(400) previous = category.get_previous_category() if not previous: self.abort(400) _swap_sequence_numbers(previous, category) category.put() previous.put() self.response.headers["Content-Type"] = "application/json" self.response.write(json.dumps({ 'success': True, 'category_id': category.key.id(), 'previous_id': previous.key.id() }, separators=(',', ':')))
def post(self): category_id = self.request.get_range('category_id') category = MenuCategory.get_by_id(category_id) if not category: self.abort(400) category.title = self.request.get('title') if self.request.get('image_file'): new_url = get_new_image_url('MenuCategory', category.key.id(), image_data=str(self.request.get('image_file'))) elif self.request.get('picture'): new_url = get_new_image_url('MenuCategory', category.key.id(), url=self.request.get('picture')) else: new_url = None category.picture = new_url if category.picture: category.icon = get_new_image_url('MenuCategoryIcon', category.key.id(), url=category.picture, size=ICON_SIZE) else: category.icon = None category.put() self.redirect_to('mt_category_list')
def post(self): category_id = self.request.get_range('category_id') category = MenuCategory.get_by_id(category_id) if not category: self.abort(400) product_id = self.request.get_range('product_id') item = MenuItem.get_by_id(product_id) if not item: self.abort(400) item.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)) else: item.price = 0 item.kal = self.request.get_range('kal') if self.request.get('volume') and self.request.get('volume') != 'None': item.volume = float(self.request.get('volume')) else: item.volume = 0 if self.request.get('weight') and self.request.get('weight') != 'None': item.weight = float(self.request.get('weight')) else: item.weight = 0 item.picture = None item.cut_picture = None item.icon = None 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.put() self.redirect('/company/menu/item/list?category_id=%s' % category_id)
def get(self): promo_id = self.request.get_range('promo_id') promo = Promo.get_by_id(promo_id) if not promo: self.abort(400) feature_type = self.request.get_range('feature_type') if feature_type not in FEATURES_TYPES: self.abort(400) number = self.request.get_range('number') if feature_type == OUTCOME: if len(promo.outcomes) <= number: self.abort(400) feature = promo.outcomes[number] feature_name = OUTCOME_MAP[feature.method] elif feature_type == CONDITION: if len(promo.conditions) <= number: self.abort(400) feature = promo.conditions[number] feature_name = CONDITION_MAP[feature.method] else: feature_name = u'Не найдено' feature = None categories = MenuCategory.query().fetch() for category in categories: items = [] for item in category.get_items(): if item.key == feature.item_details.item: item.has = True else: item.has = False items.append(item) category.items = items self.render( '/promos/choose_product.html', **{ 'categories': categories, 'promo': promo, 'feature': feature, 'feature_name': feature_name, 'feature_number': number, })
def get(self): venue_id = self.request.get_range('venue_id') venue_key = ndb.Key('Venue', venue_id) venue = Venue.get_by_id(venue_id) if not venue: self.abort(400) categories = [] for category in MenuCategory.query().fetch(): products = [] for product in category.get_items(only_available=True): if venue_key in product.restrictions: product.avail = False else: product.avail = True products.append(product) category.products = products if products: categories.append(category) self.render('/menu/select_products_restriction.html', **{ 'categories': categories, 'venue': venue })
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 post(self): data = json.loads(self.request.body) name, phone, email = map(data['info'].get, ('name', 'phone', 'email')) phone = '7' + ''.join(c for c in phone if '0' <= c <= '9') namespace = self._find_namespace(name) password = "******" % random.randint(0, 10000) CompanyUser.create_user(namespace, namespace=namespace, password_raw=password, login=namespace, rights=CompanyUser.RIGHTS_MASK_ADMIN) namespace_manager.set_namespace(namespace) cfg = Config(id=1) cfg.APP_NAME = name cfg.DELIVERY_PHONES = [phone] cfg.DELIVERY_EMAILS = ['*****@*****.**', email] cfg.SUPPORT_EMAILS = [email] cfg.ACTION_COLOR = "FF25B8CD" cfg.put() delivery_slot_keys = [ DeliverySlot(name=u'Сейчас', slot_type=0, value=0).put(), DeliverySlot(name=u'Через 5 минут', slot_type=0, value=5).put(), DeliverySlot(name=u'Через 10 минут', slot_type=0, value=10).put(), DeliverySlot(name=u'Через 15 минут', slot_type=0, value=15).put(), DeliverySlot(name=u'Через 20 минут', slot_type=0, value=20).put(), DeliverySlot(name=u'Через 25 минут', slot_type=0, value=25).put(), DeliverySlot(name=u'Через 30 минут', slot_type=0, value=30).put() ] menu = data['menu'] init = MenuCategory(category=None, title="Init") init.put() for i, category_dict in enumerate(menu): MenuCategory.generate_category_sequence_number( ) # only to increase counter category = MenuCategory(title=category_dict["title"], sequence_number=i, category=init.key) category.put() for j, item in enumerate(category_dict["items"]): MenuItem(category=category.key, title=item["title"], description=item["description"], picture=item["imageUrl"], price=int(round(float(item["price"]) * 100)), sequence_number=j).put() for _ in category.get_items(): category.generate_sequence_number() # only to increase counter venue_dict = data['venue'] venue = Venue(title=venue_dict['title'], description=venue_dict['address'], coordinates=ndb.GeoPt(venue_dict['lat'], venue_dict['lng']), active=True) venue.update_address() venue.schedule = Schedule(days=[ DaySchedule( weekday=i, start=datetime.time(0, 0), end=datetime.time(0, 0)) for i in xrange(1, 8) ]) for delivery_type in (SELF, IN_CAFE): delivery = DeliveryType.create(delivery_type) delivery.put() delivery.status = STATUS_AVAILABLE delivery.max_time = DAY_SECONDS + HOUR_SECONDS # need hour to order on tomorrow delivery.delivery_slots = delivery_slot_keys venue.delivery_types.append(delivery) venue.put() PaymentType(id=str(CASH_PAYMENT_TYPE), title="cash", status=STATUS_AVAILABLE).put() deferred.defer(_notify_sms, phone, namespace, password) deferred.defer(_notify_email, email, phone, name, namespace, password) self.render_json({'login': namespace, 'password': password})
def get(self): main_category_id = self.request.get_range('main_category_id') main_category = MenuCategory.get_by_id(main_category_id) if not main_category: self.abort(400) self.render('/menu/add_category.html', main_category=main_category)
def post(self): main_category_id = self.request.get_range('main_category_id') main_category = MenuCategory.get_by_id(main_category_id) if not main_category: self.abort(400) category = MenuCategory(sequence_number=MenuCategory.generate_category_sequence_number(), category=main_category.key) category.title = self.request.get('title') category.put() if self.request.get('image_file') or self.request.get('picture'): if self.request.get('image_file'): new_url = get_new_image_url('MenuCategory', category.key.id(), image_data=str(self.request.get('image_file'))) elif self.request.get('picture'): new_url = get_new_image_url('MenuCategory', category.key.id(), url=self.request.get('picture')) else: new_url = None if new_url: category.picture = new_url if category.picture: category.icon = get_new_image_url('MenuCategoryIcon', category.key.id(), url=category.picture, size=ICON_SIZE) category.put() self.redirect_to('mt_category_list')
def get(self): category_id = self.request.get_range('category_id') category = MenuCategory.get_by_id(category_id) if not category: self.abort(400) self.render('/menu/add_item.html', category=category)
def get_categories(parent): if parent.key.id() == MenuCategory.get_initial_category().key.id(): return _get_menu()[0] else: return []
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()