def menuItemCoursesXML(): courses = db.getAllCourses() xml = Element('restaurants') child = SubElement(xml, 'courses') for course in courses: child.append(course.serialize_xml) return xmlResponse(xml)
def editMenuItem(restaurant_id, menu_id): # Get user info for the user menu user = userData.getCurrentUserInfo() # Fetches the context item item = db.getRestaurantMenuItem( menu_id ) # Checks whether the user has access to this content if not allowAccess( item.user_id, user["id"] ): # Inform the user output = "You are not authorized to edit menu items to %s restaurant. Please create your own restaurant in order to edit items." % restaurant.name flash(output, "alert-danger") # Redirects to the new area return redirect( url_for('showmenu', restaurant_id = restaurant_id) ) # Fetches all courses type courses = db.getAllCourses() if request.method == 'POST': if validateStateToke( request.form['csrf'] ): money = request.form['price'] value = Decimal(sub(r'[^\d.]', '', money)) name = request.form['name'] db.updateRestaurantMenuItem( item, name = name, description = request.form['description'], price = '${:,.2f}'.format(float(value)), course_name = request.form['course'], ) # Inform the user output = "%s menu item edited!" % name flash( output, "alert-success" ) # Redirects to the new area return redirect(url_for('showmenu', restaurant_id = restaurant_id)) else: # Convert price to number item.price = Decimal(sub(r'[^\d.]', '', item.price)) # Render template return render_template( 'editMenuItem.html', restaurant_id = restaurant_id, menu_id = menu_id, item = item, courses = courses, token = antiForgeryGenToke(), username = user['name'], user_picture = user['picture'] )
def editMenuItem(restaurant_id, menu_id): # Get user info for the user menu user = userData.getCurrentUserInfo() # Fetches the context item item = db.getRestaurantMenuItem(menu_id) # Checks whether the user has access to this content if not allowAccess(item.user_id, user["id"]): # Inform the user output = "You are not authorized to edit menu items to %s restaurant. Please create your own restaurant in order to edit items." % restaurant.name flash(output, "alert-danger") # Redirects to the new area return redirect(url_for('showmenu', restaurant_id=restaurant_id)) # Fetches all courses type courses = db.getAllCourses() if request.method == 'POST': if validateStateToke(request.form['csrf']): money = request.form['price'] value = Decimal(sub(r'[^\d.]', '', money)) name = request.form['name'] db.updateRestaurantMenuItem( item, name=name, description=request.form['description'], price='${:,.2f}'.format(float(value)), course_name=request.form['course'], ) # Inform the user output = "%s menu item edited!" % name flash(output, "alert-success") # Redirects to the new area return redirect(url_for('showmenu', restaurant_id=restaurant_id)) else: # Convert price to number item.price = Decimal(sub(r'[^\d.]', '', item.price)) # Render template return render_template('editMenuItem.html', restaurant_id=restaurant_id, menu_id=menu_id, item=item, courses=courses, token=antiForgeryGenToke(), username=user['name'], user_picture=user['picture'])
def NewMenuItem(restaurant_id): # Get user info for the user menu user = userData.getCurrentUserInfo() # Fetches the context restaurant restaurant = db.getRestaurant( restaurant_id ) # Checks whether the user has access to this content if not allowAccess( restaurant.user_id, user["id"] ): # Inform the user output = "You are not authorized to add menu items to %s restaurant. Please create your own restaurant in order to add items." % restaurant.name flash(output, "alert-danger") # Redirects to the new area return redirect( url_for('showmenu', restaurant_id = restaurant_id) ) # Fetches all courses type courses = db.getAllCourses() if request.method == 'POST': if validateStateToke( request.form['csrf'] ): # Save the new menu item db.newRestaurantMenuItem( name = request.form['name'], restaurant_id = restaurant_id, description = request.form['description'], price = '${:,.2f}'.format(float(request.form['price'])), user_id = user["id"], course_name = request.form['course'] ) # Inform the user flash("New menu item created!", "alert-success") # Redirects to the new area return redirect( url_for('showmenu', restaurant_id = restaurant_id) ) else: # Render template return render_template( 'newMenuItem.html', restaurant = restaurant, courses = courses, token = antiForgeryGenToke(), username = user['name'], user_picture = user['picture'] )
def NewMenuItem(restaurant_id): # Get user info for the user menu user = userData.getCurrentUserInfo() # Fetches the context restaurant restaurant = db.getRestaurant(restaurant_id) # Checks whether the user has access to this content if not allowAccess(restaurant.user_id, user["id"]): # Inform the user output = "You are not authorized to add menu items to %s restaurant. Please create your own restaurant in order to add items." % restaurant.name flash(output, "alert-danger") # Redirects to the new area return redirect(url_for('showmenu', restaurant_id=restaurant_id)) # Fetches all courses type courses = db.getAllCourses() if request.method == 'POST': if validateStateToke(request.form['csrf']): # Save the new menu item db.newRestaurantMenuItem(name=request.form['name'], restaurant_id=restaurant_id, description=request.form['description'], price='${:,.2f}'.format( float(request.form['price'])), user_id=user["id"], course_name=request.form['course']) # Inform the user flash("New menu item created!", "alert-success") # Redirects to the new area return redirect(url_for('showmenu', restaurant_id=restaurant_id)) else: # Render template return render_template('newMenuItem.html', restaurant=restaurant, courses=courses, token=antiForgeryGenToke(), username=user['name'], user_picture=user['picture'])
def menuItemCoursesJSON(): courses = db.getAllCourses() return jsonify( courses=[course.serialize_json for course in courses] )
def menuItemCoursesJSON(): courses = db.getAllCourses() return jsonify(courses=[course.serialize_json for course in courses])