示例#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