Пример #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'])
Пример #2
0
def deleteMenuItem(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 delete menu item to %s. Please create your own restaurant in order to delete items." % item.name
        flash(output, "alert-danger")
        # Redirects to the new area
        return redirect(url_for('showmenu', restaurant_id=restaurant_id))

    if request.method == 'POST':
        if validateStateToke(request.form['csrf']):
            # Deleting item
            db.deleteRestaurantMenuItem(item)

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

        # Redirects to the new area
        return redirect(url_for('showmenu', restaurant_id=restaurant_id))
    else:
        # Render template
        return render_template('deleteMenuItem.html',
                               restaurant_id=restaurant_id,
                               menu_id=menu_id,
                               item=item,
                               token=antiForgeryGenToke(),
                               username=user['name'],
                               user_picture=user['picture'])
Пример #3
0
def newRestaurant():
    # Get user info for the user menu
    user = userData.getCurrentUserInfo()
    
    if request.method == 'POST':
        
        file_path = filesHandler.uploadImage( request.files['file'] )
        
        # Save the new restaurant
        db.newRestaurant( 
            name = request.form['name'],
            file = file_path,
            user_id = user["id"] 
        )
        
        # Inform the user
        flash("New restaurant created!", "alert-success")

        # Redirects to the new area
        return redirect( url_for('showRestaurants') )
    else:
        # Render template
        return render_template( 
            'newRestaurant.html', 
            username = user['name'],
            user_picture = user['picture'] 
        )
Пример #4
0
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'] 
        )
Пример #5
0
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'])
Пример #6
0
def showRestaurants():
    # Get user info for the user menu
    user = userData.getCurrentUserInfo()

    # Fetch restaurants
    restaurants = db.getAllRestaurants()

    # Render template
    return render_template('restaurants.html',
                           filesPath=filesHandler.getFilesFolder(),
                           restaurants=list(restaurants),
                           username=user['name'],
                           user_id=user['id'],
                           user_picture=user['picture'])
Пример #7
0
def showRestaurants():
    # Get user info for the user menu
    user = userData.getCurrentUserInfo()
    
    # Fetch restaurants
    restaurants = db.getAllRestaurants()
    
    # Render template
    return render_template(
        'restaurants.html',
        filesPath = filesHandler.getFilesFolder(),
        restaurants = list(restaurants), 
        username = user['name'], 
        user_id = user['id'], 
        user_picture = user['picture']
    )
Пример #8
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'] 
        )
Пример #9
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'])
Пример #10
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'] 
        )
Пример #11
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'])
Пример #12
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'])
Пример #13
0
def newRestaurant():
    # Get user info for the user menu
    user = userData.getCurrentUserInfo()

    if request.method == 'POST':

        file_path = filesHandler.uploadImage(request.files['file'])

        # Save the new restaurant
        db.newRestaurant(name=request.form['name'],
                         file=file_path,
                         user_id=user["id"])

        # Inform the user
        flash("New restaurant created!", "alert-success")

        # Redirects to the new area
        return redirect(url_for('showRestaurants'))
    else:
        # Render template
        return render_template('newRestaurant.html',
                               username=user['name'],
                               user_picture=user['picture'])
Пример #14
0
def deleteMenuItem(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 delete menu item to %s. Please create your own restaurant in order to delete items." % item.name
        flash(output, "alert-danger")
        # Redirects to the new area
        return redirect( url_for('showmenu', restaurant_id = restaurant_id) )

    if request.method == 'POST':
        if validateStateToke( request.form['csrf'] ):
            # Deleting item
            db.deleteRestaurantMenuItem( item )

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

        # Redirects to the new area
        return redirect(url_for('showmenu', restaurant_id = restaurant_id))
    else:
        # Render template
        return render_template(
            'deleteMenuItem.html', 
            restaurant_id = restaurant_id, 
            menu_id = menu_id, 
            item = item, 
            token = antiForgeryGenToke(),
            username = user['name'],
            user_picture = user['picture'] 
        )
Пример #15
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'] 
    )
Пример #16
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'] 
        )
Пример #17
0
 def decorated_function(*args, **kwargs):
     user = userData.getCurrentUserInfo()
     if not user['name']:
         flash("Authentication required", "alert-danger")
         return redirect(url_for('showLogin'))
     return func(*args, **kwargs)
Пример #18
0
 def decorated_function(*args, **kwargs):
     user = userData.getCurrentUserInfo()
     if not user['name']:
         flash("Authentication required", "alert-danger")
         return redirect( url_for('showLogin') )
     return func(*args, **kwargs)