def reset_database():
    # run db_drop to reset the database
    db_drop(db)

    # run db_create to initialize the database
    db_create(db)

    # run db_seed to create sample data in the database
    db_seed(db)

    # update the js file
    update_js()
def add(product_id):
    if request.method == "POST":
        if current_user is not None:
            review_list = Reviews.query.all()
            maxi = 1
            for review in review_list:
                if review.review_id >= maxi:
                    maxi = review.review_id + 1
            review = Reviews(review_id=maxi,
                             id=current_user.id,
                             product_id=product_id,
                             review=re.escape(request.form['comment']))
            db.session.add(review)
            db.session.commit()
            update_js()
    return redirect(url_for('home'))
Beispiel #3
0
def add(product_id):
    if request.method == "POST":
        if current_user is not None:
            statement = text("SELECT review_id FROM reviews")
            result = db.engine.execute(statement)
            maxi = 1
            for row in result:
                if row[0] >= maxi:
                    maxi = row[0] + 1
            review = Reviews(review_id=maxi,
                             id=current_user.id,
                             product_id=product_id,
                             review=request.form['comment'])
            db.session.add(review)
            db.session.commit()
            statement = text("SELECT * FROM reviews")
            result = db.engine.execute(statement)
            for row in result:
                print(row)
            update_js()
    return redirect(url_for('home'))