示例#1
0
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
示例#2
0
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
示例#3
0
 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')
示例#4
0
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()