def edit_menu_item(restaurant_id, menu_id):
    # Make sure user is logged on first
    if 'username' not in login_session:
        return redirect(url_for('login'))
    item = crud.get_menu_item(menu_id)
    form = MenuForm(request.form)
    form.course.choices = [('Appetizer', 'Appetizer'),
                           ('Entree', 'Entree'),
                           ('Beverage', 'Beverage'),
                           ('Dessert', 'Dessert')]
    if request.method == 'GET':
        # Set values for form
        form.name.data = item.name
        form.course.data = item.course
        form.description.data = item.description
        form.price.data = item.price
    if request.method == 'POST' and form.validate():
        # Get data from form and then use CRUD function to update
        name = form.name.data
        description = form.description.data
        course = form.course.data
        price = form.price.data
        crud.edit_menu_item(menu_id, name, description, course, price)
        flash("Menu Item Successfully Edited")
        return redirect(url_for('show_menu', restaurant_id=restaurant_id))
    return render_template('/menu/edit_menu_item.html', menu_item=item, restaurant_id=restaurant_id, form=form)
def api_menu_item(menu_id):
    """Returns JSON data a single menu item, and XML if ?type=xml is used"""
    menu_item = crud.get_menu_item(menu_id)
    if request.args.get('type') == 'xml':
        xml = dicttoxml(menu_item.serialize, attr_type=False)
        return Response(xml, mimetype='text/xml')
    else:
        return jsonify(menu_item.serialize)
def delete_menu_item(restaurant_id, menu_id):
    # Make sure user is logged on first
    if 'username' not in login_session:
        return redirect(url_for('login'))
    if request.method == 'GET':
        item = crud.get_menu_item(menu_id)
        return render_template('/menu/delete_menu_item.html', menu_item=item, restaurant_id=restaurant_id)
    if request.method == 'POST':
        crud.delete_menu_item(menu_id)
        flash("Menu Item Successfully Deleted")
        return redirect(url_for('show_menu', restaurant_id=restaurant_id))