コード例 #1
0
ファイル: views.py プロジェクト: MarcoPires/restaurantApp
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'] 
        )
コード例 #2
0
ファイル: views.py プロジェクト: MarcoPires/restaurantApp
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'] 
        )
コード例 #3
0
ファイル: views.py プロジェクト: MarcoPires/restaurantApp
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'])
コード例 #4
0
ファイル: views.py プロジェクト: MarcoPires/restaurantApp
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'])