Example #1
0
def deleteRestaurant(restaurant_id):
    # Get user info for the user menu
    user = userData.getCurrentUserInfo()

    # Fetches the restaurant to delete
    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 delete the %s restaurant. Please create your own restaurant in order to delete!" % restaurant.name
        flash(output, "alert-danger")
        # Redirects to the new area
        return redirect(url_for('showRestaurants'))

    if request.method == 'POST':

        if validateStateToke(request.form['csrf']):
            # Deleting from database
            db.deleteRestaurant(restaurant)

            # Inform the user
            output = "Restaurant %s was deleted!" % restaurant.name
            flash(output, "alert-success")

        # Redirects to the new area
        return redirect(url_for('showRestaurants'))
    else:
        # Render template
        return render_template('deleteRestaurant.html',
                               restaurant=restaurant,
                               token=antiForgeryGenToke(),
                               username=user['name'],
                               user_picture=user['picture'])
Example #2
0
def showMenuXML(restaurant_id): 
    restaurant = db.getRestaurant( restaurant_id )
    items      = db.getAllRestaurantMenuItems( restaurant )
    
    xml = Element('restaurant')
    xml.set('id', str(restaurant.id))
    xml.set('name', restaurant.name)
    for item in items:
        xml.append(item.serialize_xml)

    return xmlResponse(xml)
Example #3
0
def showMenuXML(restaurant_id):
    restaurant = db.getRestaurant(restaurant_id)
    items = db.getAllRestaurantMenuItems(restaurant)

    xml = Element('restaurant')
    xml.set('id', str(restaurant.id))
    xml.set('name', restaurant.name)
    for item in items:
        xml.append(item.serialize_xml)

    return xmlResponse(xml)
Example #4
0
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'] 
        )
Example #5
0
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'])
Example #6
0
def editRestaurant(restaurant_id):
    # Get user info for the user menu
    user = userData.getCurrentUserInfo()
    
    # Fetches the restaurant to edit
    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 edit the %s restaurant. Please create your own restaurant in order to edit!" % restaurant.name
        flash(output, "alert-danger")
        # Redirects to the new area
        return redirect( url_for('showRestaurants') )

    if request.method == 'POST':
        
        if validateStateToke( request.form['csrf'] ):
            # Save the edited restaurant
            name = request.form['name']
            
            file_path = filesHandler.uploadImage( request.files['file'] )
            print "----------->"
            db.updateRestaurant( restaurant = restaurant, 
                name = name, picture = file_path )

            # Inform the user
            output = "Restaurant %s was edited!" % name
            flash( output, "alert-success" )
        
        # Redirects to the new area
        return redirect( url_for('showRestaurants') )
    else:
        # Render template
        return render_template(
            'editRestaurant.html', 
            restaurant = restaurant,
            token = antiForgeryGenToke(),
            username = user['name'],
            user_picture = user['picture'] 
        )
Example #7
0
def editRestaurant(restaurant_id):
    # Get user info for the user menu
    user = userData.getCurrentUserInfo()

    # Fetches the restaurant to edit
    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 edit the %s restaurant. Please create your own restaurant in order to edit!" % restaurant.name
        flash(output, "alert-danger")
        # Redirects to the new area
        return redirect(url_for('showRestaurants'))

    if request.method == 'POST':

        if validateStateToke(request.form['csrf']):
            # Save the edited restaurant
            name = request.form['name']

            file_path = filesHandler.uploadImage(request.files['file'])
            print "----------->"
            db.updateRestaurant(restaurant=restaurant,
                                name=name,
                                picture=file_path)

            # Inform the user
            output = "Restaurant %s was edited!" % name
            flash(output, "alert-success")

        # Redirects to the new area
        return redirect(url_for('showRestaurants'))
    else:
        # Render template
        return render_template('editRestaurant.html',
                               restaurant=restaurant,
                               token=antiForgeryGenToke(),
                               username=user['name'],
                               user_picture=user['picture'])
Example #8
0
def showmenu(restaurant_id):
    # Get user info for the user menu
    user = userData.getCurrentUserInfo()

    # Fetches the context restaurant
    restaurant = db.getRestaurant(restaurant_id)

    # Fetches all items from the context restaurant
    items = db.getAllRestaurantMenuItems(restaurant)

    # Fetches all courses type, and respective menu items
    courses = db.getAllRestItemsByCourses(restaurant)

    # Render template
    return render_template('menu.html',
                           filesPath=filesHandler.getFilesFolder(),
                           restaurant=restaurant,
                           items=list(items),
                           courses=courses,
                           user_id=user['id'],
                           username=user['name'],
                           user_picture=user['picture'])
Example #9
0
def showmenu(restaurant_id):
    # Get user info for the user menu
    user = userData.getCurrentUserInfo()

    # Fetches the context restaurant
    restaurant = db.getRestaurant( restaurant_id )
    
    # Fetches all items from the context restaurant
    items = db.getAllRestaurantMenuItems( restaurant )

    # Fetches all courses type, and respective menu items
    courses = db.getAllRestItemsByCourses( restaurant )

    # Render template
    return render_template(
        'menu.html',
        filesPath = filesHandler.getFilesFolder(),
        restaurant = restaurant,
        items = list(items), 
        courses = courses, 
        user_id = user['id'], 
        username = user['name'],
        user_picture = user['picture'] 
    )
Example #10
0
def deleteRestaurant(restaurant_id):
    # Get user info for the user menu
    user = userData.getCurrentUserInfo()
    
    # Fetches the restaurant to delete
    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 delete the %s restaurant. Please create your own restaurant in order to delete!" % restaurant.name
        flash( output, "alert-danger" )
        # Redirects to the new area
        return redirect( url_for('showRestaurants') )

    if request.method == 'POST':
        
        if validateStateToke( request.form['csrf'] ):
            # Deleting from database
            db.deleteRestaurant( restaurant )
            
            # Inform the user
            output = "Restaurant %s was deleted!" % restaurant.name
            flash(output, "alert-success")

        # Redirects to the new area
        return redirect( url_for('showRestaurants') )
    else:
        # Render template
        return render_template( 
            'deleteRestaurant.html',
            restaurant = restaurant,
            token = antiForgeryGenToke(),
            username = user['name'],
            user_picture = user['picture'] 
        )
Example #11
0
def showMenuJSON(restaurant_id): 
    restaurant = db.getRestaurant( restaurant_id )
    items      = db.getAllRestaurantMenuItems( restaurant )
    return jsonify( MenuItems=[i.serialize_json for i in items] )
Example #12
0
def showRestaurantJSON(restaurant_id):
    restaurant = db.getRestaurant( restaurant_id )
    return jsonify( restaurant.serialize_json )
Example #13
0
def showMenuJSON(restaurant_id):
    restaurant = db.getRestaurant(restaurant_id)
    items = db.getAllRestaurantMenuItems(restaurant)
    return jsonify(MenuItems=[i.serialize_json for i in items])
Example #14
0
def showRestaurantJSON(restaurant_id):
    restaurant = db.getRestaurant(restaurant_id)
    return jsonify(restaurant.serialize_json)
Example #15
0
def showRestaurantXML(restaurant_id):
    restaurant = db.getRestaurant( restaurant_id )
    return xmlResponse( restaurant.serialize_xml )
Example #16
0
def showRestaurantXML(restaurant_id):
    restaurant = db.getRestaurant(restaurant_id)
    return xmlResponse(restaurant.serialize_xml)