def form_valid(self, form): csv_content = form.cleaned_data['csv'] reader = csv.reader(csv_content.splitlines(), delimiter=";") for row in reader: mi = MenuItem(name=unicode(row[0]), unit_price=row[1], category_id=row[2]) mi.save() messages.success(self.request, u"Saved {name} at {price}€".format(name=row[0], price=row[1])) return super(ImportMenuItemsFormView, self).form_valid(form)
def createMenuItem(self, id=1): with self.app.app_context(): menu_item = MenuItem.query.get(id) if not menu_item: menu = Menu.query.get(1) if not menu: menu = Menu(category=MenuType.BREAKFAST) menu.save() meal_name = 'ugali' meal = Meal.query.filter_by(name=meal_name).first() if not meal: meal = Meal(name=meal_name, img_path='#', cost=200) meal.save() menu_item = MenuItem(menu_id=menu.id, meal_id=meal.id) menu_item.save() return menu_item.id
def mgmt(): add_menu_form = MenuItemAddForm() add_addon_form = AddOnAddForm() if add_menu_form.validate_on_submit(): add_item = MenuItem(menu_item_number=add_menu_form.itemnumber.data, item_name=add_menu_form.name.data, price=add_menu_form.price.data, drink_type=add_menu_form.drinktype.data, drink_description=add_menu_form.description.data) db.session.add(add_item) db.session.commit() flash('Menu item added successfully.') return redirect('/mgmt') if add_addon_form.validate_on_submit(): add_item = AddOnItem(add_on_number=add_addon_form.addonnumber.data, food_description=add_addon_form.description.data, price=add_addon_form.price.data, foodstatus=add_addon_form.availability.data) db.session.add(add_item) db.session.commit() flash('Add on item added successfully.') return redirect('/mgmt') item_list = MenuItem.query.all() addon_list = AddOnItem.query.all() return render_template('mgmt.html', title='Management', item_list=item_list, addon_list=addon_list, add_menu_form=add_menu_form, add_addon_form=add_addon_form)
def create_menu_item(): """ Endpoint for creating a menu item. Returns 500 if the item cannot be created. """ data = json.loads(request.data) menu_item = MenuItem(item_name=data['name'], item_desc=data['description'], item_price=data['price'], item_type=data['type'], img=data['img'], in_stock=data['in_stock']) new_item_id = MenuController.create_menu_item(menu_item) if not new_item_id: return jsonify({ 'status': 'Failed', 'message': 'Problem creating a new menu item.' }), 500 return jsonify({ 'status': 'Success', 'message': f'Item added with id: {new_item_id}.' }), 201
def install_data(): for setting in default_settings: db.session.add(setting) for i, (name, url) in enumerate(pages, 1): page = Page(name=name, url=url, template=u'page.html', position=i) db.session.add(page) for i, (name, page_id, parent_id) in enumerate(menu, 1): menuitem = MenuItem(name=name, page_id=page_id, parent_id=parent_id, position=i) db.session.add(menuitem) sec1html = u'<p>Content for pages can be written in the administration panel' \ u' under Content -> Pages or Content -> Sections.</p>' section = Section(name=u'Introduction', html=sec1html, page_id=1, template=u'section.html', position=1) db.session.add(section) section = Section(name=u'Members', html=u'', page_id=2, template=u'members.html', position=1) db.session.add(section) mem1desc = u'<p>Information about team members can be written in the administration panel' \ u' under Content -> Entities.</p><p>Entities with role assigned as Member will be shown here.</p>' member = Entity(name=u'Team Member 1', description=mem1desc, role=u'Member', position=1) db.session.add(member) member = Entity(name=u'Team Member 2', description=u'', role=u'Member', position=2) db.session.add(member) db.session.commit()
def new_menu_item(rest_id): user = current_user form = forms.NewMenuItem(request.form) restaurant = session.query(Restaurant).filter_by(id=rest_id).one() if user.id != restaurant.user_id: flash("You don't have permission to edit this information.") return redirect(url_for('show_menu', rest_id=restaurant.id)) if request.method == 'POST': name = form.name.data description = form.description.data price = form.price.data course = form.course.data menu = MenuItem(name=name, description=description, price=price, course=course, restaurant=restaurant, user=user) session.add(menu) session.commit() return redirect(url_for('show_menu', rest_id=rest_id)) return render_template('new_menu.html', restaurant=restaurant, form=form)
def newMenuItem(restaurant_id): restaurant = Restaurant.query.filter_by(id=restaurant_id).one() # only the user who created the resturant is allowed to add a entry # TODO: add a admin user if restaurant.user_id != session['user']['user_id']: # TODO: implement better way to handle authorization return "<script>function permissionDenied() {alert('You do not have permission for this action.')}</script><body onload=permissionDenied()>" if request.method == 'POST': newItem = MenuItem(name=request.form['name'], description=request.form['description'], price=request.form['price'], course=request.form['course'], restaurant_id=restaurant_id, user_id=session['user']['user_id']) db.session.add(newItem) db.session.commit() flash('New Menu %s Item Successfully Created' % (newItem.name)) return redirect(url_for('showMenu', restaurant_id=restaurant_id)) else: return flask.render_template('newmenuitem.html', restaurant_id=restaurant_id)
with app.app_context(): db.drop_all() db.create_all() employee = Employee(name='Margot', employee_number=1234, password='******') dinner = Menu(name='Dinner') beverages = MenuItemType(name='Beverages') entrees = MenuItemType(name='Entrees') sides = MenuItemType(name='Sides') fries = MenuItem(name='French fries', price=3.50, type=sides, menus=dinner) drp = MenuItem(name='Dr. Pepper', price=1.0, type=beverages, menus=dinner) jambalaya = MenuItem(name='Jambalaya', price=21.98, type=entrees, menus=dinner) table1 = 1 table2 = 2 table3 = 3 table4 = 4 table5 = 5 table6 = 6 table7 = 7 table8 = 8 table9 = 9
with app.app_context(): db.drop_all() db.create_all() employee = Employee(name="Margot", employee_number=1234, password="******") beverages = MenuItemType(name="Beverages") entrees = MenuItemType(name="Entrees") sides = MenuItemType(name="Sides") dinner = Menu(name="Dinner") fries = MenuItem(name="French fries", price=3.50, type=sides, menu=dinner) drp = MenuItem(name="Dr. Pepper", price=1.0, type=beverages, menu=dinner) jambalaya = MenuItem(name="Jambalaya", price=21.98, type=entrees, menu=dinner) i = 1 while i < 11: db.session.add(Table(number=i, capacity=randint(1, 20))) i += 1 db.session.add(dinner) db.session.add(employee) db.session.commit()
from dotenv import load_dotenv load_dotenv() from app.models import db from app import app from app.models import Employee, Menu, MenuItem, MenuItemType, Table with app.app_context(): # db.drop_all() # db.create_all() user = Employee(name="Margot", employee_number=1234, password="******") beverages = MenuItemType(name="Beverages") entrees = MenuItemType(name="Entrees") sides = MenuItemType(name="Sides") dinner = Menu(name="Dinner") fries = MenuItem(name="French fries", price=3.50, type=sides, menu=dinner) drp = MenuItem(name="Dr. Pepper", price=1.0, type=beverages, menu=dinner) tea = MenuItem(name="Lingonberry Tea", price=1.0, type=beverages, menu=dinner) jambalaya = MenuItem(name="Jambalaya", price=21.98, type=entrees, menu=dinner) parm = MenuItem(name="Eggplant Parmesan", price=21.98, type=entrees, menu=dinner) for index in range(1, 11): db.session.add(Table(capacity=index, number=index)) db.session.add(dinner) db.session.add(user) db.session.commit()
'https://pbs.twimg.com/profile_images/2671170543/18debd694829ed78203a5a36dd364160_400x400.png' ) db.session.add(User1) db.session.commit() # Menu for UrbanBurger restaurant1 = Restaurant(user_id=1, name="Urban Burger") db.session.add(restaurant1) db.session.commit() menu_items1 = [ MenuItem( user_id=1, name="Veggie Burger", description="Juicy grilled veggie patty with tomato mayo and lettuce", price="$7.50", course="Entree", restaurant=restaurant1), MenuItem(user_id=1, name="French Fries", description="with garlic and parmesan", price="$2.99", course="Appetizer", restaurant=restaurant1), MenuItem( user_id=1, name="Chicken Burger", description="Juicy grilled chicken patty with tomato mayo and lettuce", price="$5.50", course="Entree",