Exemple #1
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
Exemple #2
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')