Beispiel #1
0
def UpdatetimeEdit():

    mycursor = app.config["DATABASE"].cursor()
    query = "SELECT period FROM time_period WHERE time_period.time ='" + str(
        request.form["theTime"]) + "';"
    mycursor.execute(query)
    period = mycursor.fetchall()[0][0]
    restaurant = Restaurant.fetchRestaurant(request.form["theRestaurant"])
    dateSelected = request.form["dateSelected"]
    # from db_methods
    times = db_get_times(period)
    query = "SELECT timeid,TIME_FORMAT(time,'%H:%i') FROM time_period WHERE period='" + str(
        period) + "';"
    mycursor.execute(query)
    times = mycursor.fetchall()
    mycursor.execute(
        "INSERT INTO booking_info VALUES(36,1,'01'),(37,2,'02'),(38,3,'03'),(39,3,'04'),(40,4,'05')"
    )
    app.config["DATABASE"].commit()
    mycursor.execute(
        "INSERT INTO rest_book VALUES(1,36,'01','2018-12-09',5,3),(1,37,'02','2018-12-09',5,2),(1,38,'03','2018-12-09',5,2),(1,39,'04','2018-12-09',5,2),(1,40,'05','2018-12-09',5,3)"
    )
    app.config["DATABASE"].commit()
    fullTimes = timeDisabled(dateSelected, times, period)
    mycursor.execute(
        "DELETE FROM rest_book WHERE rest_book.bid IN(36,37,38,39,40)")
    mycursor.execute(
        "DELETE FROM booking_info WHERE booking_info.bid IN(36,37,38,39,40)")
    app.config["DATABASE"].commit()
    timesButton = buildTimesButtons(times, fullTimes=fullTimes)
    return render_template("editPage/timeEdit.html",
                           times=timesButton,
                           restaurant=restaurant)
Beispiel #2
0
def create_restuarant():
    req = request.json
    required = [
        "restaurant_name", "restaurant_description", "restaurant_img_url"
    ]

    if not all(k in req for k in required):
        return jsonify({"message": "Missing Required Values"}), 400

    restaurant_name = req["restaurant_name"]
    restaurant_description = req["restaurant_description"]
    restaurant_img_url = req["restaurant_img_url"]
    restaurant_rating = assign_req_values(req, "restuarant_rating", None)
    restaurant_location = assign_req_values(req, "restaurant_location", None)
    restaurant_hours_of_operation = assign_req_values(
        req, "restaurant_hours_of_operation", None)

    new_restaurant = Restaurant(
        restaurant_name=restaurant_name,
        restaurant_description=restaurant_description,
        restaurant_img_url=restaurant_img_url,
        restaurant_rating=restaurant_rating,
        restaurant_location=restaurant_location,
        restaurant_hours_of_operation=restaurant_hours_of_operation,
    )
    db.session.add(new_restaurant)
    db.session.commit()
    return jsonify({"message": "Successfully add restaurant"}), 201
Beispiel #3
0
def dateAndTimeCheckEdit(bid):
    theName = request.form["theName"]
    thePhone = request.form["thePhone"]
    theEmail = request.form["theEmail"]
    selectedRestaurant = Restaurant.fetchRestaurant(
        request.form["theRestaurant"])
    theAddress = selectedRestaurant.street + ' , ' + str(
        selectedRestaurant.zip)
    theDate = request.form["theDate"]
    thePeople = request.form["thePeople"]
    theTime = request.form["theTime"]
    # bid = request.form["theBid"]
    # date = theDate.strftime('%Y-%m-%d')
    timeid = db_get_timeid(theTime)

    update_rest_book(bid, theDate, timeid, thePeople)

    return render_template("editPage/confirmDateEdit.html",
                           theDate=theDate,
                           theTime=theTime,
                           theRestaurant=selectedRestaurant,
                           theName=theName,
                           thePeople=thePeople,
                           thePhone=thePhone,
                           theEmail=theEmail,
                           theBid=bid)
Beispiel #4
0
def chooseTableSelectionEdit(bid):
    global selectedTime
    selectedTime = request.form["selectedTime"]
    theName = request.form["theName"]
    thePhone = request.form["thePhone"]
    theEmail = request.form["theEmail"]
    theRestaurant = Restaurant.fetchRestaurant(request.form["theRestaurant"])
    return render_template("editPage/buttonsTableEdit.html",
                           restaurant=theRestaurant,
                           theName=theName,
                           thePhone=thePhone,
                           theEmail=theEmail,
                           theBid=bid)
Beispiel #5
0
def db_fetch_restaurants():
    mycursor = app.config["DATABASE"].cursor()
    try:
        sql = "SELECT * FROM restaurant"
        mycursor.execute(sql)
        restaurants = mycursor.fetchall()
    except mysql.connector.Error as err:
        print("Error: {}".format(err.msg))
    finally:
        mycursor.close()

    list_of_restaurants = []
    for r in restaurants:
        r1 = Restaurant(r[0], r[1], r[2], r[3], r[4], float(r[5]), float(r[6]))
        list_of_restaurants.append(r1)
    return list_of_restaurants
Beispiel #6
0
def get_restaurant_by_id(restaurant_id: str) -> Restaurant:
    with connection.cursor(cursor_factory=extras.RealDictCursor) as cursor:
        get_restaurant_query = qb.build_get_restaurant_by_id_query(
            restaurant_id)
        cursor.execute(get_restaurant_query)
        restaurant = cursor.fetchone()
        if restaurant is None:
            raise psycopg2.DataError("Not found")

        get_tags_query = qb.build_get_tags_by_restaurant_id_query(
            restaurant_id)
        cursor.execute(get_tags_query)

        if cursor.rowcount > 0:
            tags = [str(row['tag']) for row in cursor.fetchall()]
        else:
            tags = []

        return Restaurant(tags=tags, **restaurant)
Beispiel #7
0
def dateAndTimeCheck():
    theName = request.form["theName"]
    thePhone = request.form["thePhone"]
    theEmail = request.form["theEmail"]
    theRestaurant = Restaurant.fetchRestaurant(request.form["restaurant"])
    theRid = theRestaurant.rid
    theAddress = theRestaurant.street + ' , ' + str(theRestaurant.zip)
    theDate = datetime.date(datetime.strptime(request.form["date"],
                                              "%Y-%m-%d"))
    thePeople = request.form["people"]
    theTime = request.form["time"]
    theTables = request.form["tables"]
    print("rid = ", theRid)
    if (theEmail != ''):  # if we confirm booking
        _bid = store_booking(theName, theEmail, theAddress, theDate, thePeople,
                             theTime, theRid, theTables, thePhone)
        send_mail(theName, theEmail, theRestaurant.name, theAddress,
                  theDate.strftime("%d/%m/%Y"), thePeople, theTime, _bid)
        return render_template("confirmPage/confirmDate.html",
                               theDate=theDate,
                               theTime=theTime,
                               theRestaurant=theRestaurant,
                               theName=theName,
                               thePeople=thePeople,
                               thePhone=thePhone,
                               theEmail=theEmail,
                               rid=theRid,
                               theTables=theTables,
                               theBid=_bid)
    else:
        return render_template("confirmPage/confirmDate.html",
                               theDate=theDate,
                               theTime=theTime,
                               theRestaurant=theRestaurant,
                               theName=theName,
                               thePeople=thePeople,
                               thePhone=thePhone,
                               theEmail=theEmail,
                               rid=theRid,
                               theTables=theTables,
                               theBid=0)
Beispiel #8
0
def UpdateDateEdit():

    people = request.form["people"]
    now = datetime.now()
    resto = request.form["theRestaurant"]
    restaurant = Restaurant.fetchRestaurant(request.form["theRestaurant"])
    weeks = calculCalendarWeeks(now)
    numbers = dayNumberCalendar(now)
    mycursor = app.config["DATABASE"].cursor()
    query = "SELECT * FROM period"
    mycursor.execute(query)
    periods = mycursor.fetchall()
    periodsOptions = buildSelectOptions(periods)
    calendarOptions = buildSelectOptions(weeks)
    db_insert_full_day()
    beginCalendar = now - timedelta(days=now.weekday())
    fullDays = daysDisabled(beginCalendar, periods[0][0])
    attendances = attendance(beginCalendar, periods[0][0])
    db_delete_full_day()
    templateCalendar = render_template('editPage/calendarEdit.html',
                                       numberCalendar=numbers,
                                       restaurant=restaurant,
                                       fullDays=fullDays,
                                       attendances=attendances)
    templateButtonsCalendar = render_template(
        "dateTimeTable/rowCalendarButtons.html",
        periods=periodsOptions,
        weeks=calendarOptions)
    response = {
        "calendar": templateCalendar,
        "buttonsCalendar": templateButtonsCalendar,
        "people": people,
        "currentDay": now.strftime("%Y-%m-%d"),
        "restaurantCapacity": 50
    }
    return jsonify(response)
Beispiel #9
0
def _get_restaurants_by_ids(final_ids_list: Set[str],
                            cursor: Any) -> List[Restaurant]:
    restaurants_list_query = qb.build_select_restaurants_by_ids(final_ids_list)
    cursor.execute(restaurants_list_query)
    result = cursor.fetchall()
    return [Restaurant(**r) for r in result]
Beispiel #10
0
def UpdatenumberPeople():

    theRestaurant = Restaurant.fetchRestaurant(request.form["theRestaurant"])
    return render_template("editPage/dateTimeEdit.html",
                           restaurant=theRestaurant,
                           restaurantID=request.form["theRestaurant"])
Beispiel #11
0
def dateAndTime():
    restaurantID = request.form["theRestaurant"]
    selectedRestaurant = Restaurant.fetchRestaurant(restaurantID)
    return render_template('dateTimeTable/dateTime.html',
                           restaurant=selectedRestaurant,
                           restaurantID=restaurantID)