def delete_menu_category(request, key=None): category = None if key is not None: category = MenuCategory.get(key) if key and request.method == 'POST': category.delete() return HttpResponseRedirect('/admin/menu/categories/')
def edit_menu_category(request, key=None): category = None if key is not None: category = MenuCategory.get(key) if request.method == 'POST': form = MenuCategoryForm(request.POST) if form.is_valid(): cat = MenuCategory.from_form(form) cat.put() return HttpResponseRedirect('/admin/menu/categories/') elif category: form = MenuCategoryForm({ 'name': category.name, 'description': category.description, 'column': str(category.column), 'order': category.order, # Hidden 'key': category.key()}) else: form=MenuCategoryForm() return render_admin_template('admin/menu/categories/edit.html', dict( category=category, category_form=form))
def load_fixtures(request): """Populate the data store with an initial set of data.""" fixtures = yaml.load(open(os.path.dirname(__file__) + '/../../fixtures.yaml', 'r')) menu_categories = fixtures['MenuCategory'] menu_items = fixtures['MenuItem'] categories_by_key = dict() for category in menu_categories: key = category['key'] name = category.get('name', '') description = category.get('description', '') column = category.get('column', 1) order = category.get('order', 1) cat = MenuCategory(key_name=key, name=name, description=description, column=column, order=order) cat.put() categories_by_key[key] = cat items = [] for item in menu_items: category = categories_by_key[item['category']] name = item.get('name', None) price = str(item.get('price', None)) description = item.get('description', None) show_on_menu = item.get('show_on_menu', False) item = MenuItem(category=category, name=name, price=price, description=description, show_on_menu=show_on_menu) item.put() items.append(item) return render_admin_template('admin/fixtures.html', dict( menu_items=items, menu_categories=categories_by_key.values()))
def menu(request): col1 = MenuCategory.get_by_column(1) col2 = MenuCategory.get_by_column(2) col3 = MenuCategory.get_by_column(3) return render_to_response('menu.html', dict( column_1=col1, column_2=col2, column_3=col3))