Beispiel #1
0
def update_book():
    if current_user is not None and hasattr(current_user, "id"):
        # the date and time come as string, so I have to parse them and transform them in python datetime
        #
        reservation_date = request.form.get("reservation_date")
        py_datetime = datetime.datetime.strptime(reservation_date,
                                                 "%d/%m/%Y %H:%M")
        #
        people_number = int(request.form.get("people_number"))
        #
        reservation_id = int(request.form.get("reservation_id"))

        new_book = BookingServices.update_book(
            reservation_id,
            current_user,
            py_datetime,
            people_number,
            request.form.get("friends"),
        )
        reservations_as_list = UserService.get_customer_reservation(
            None, None, current_user.id)

        form = ReservationForm()
        return render_template(
            "user_reservations.html",
            reservations_as_list=reservations_as_list,
            my_date_formatter=my_date_formatter,
            new_book=new_book,
            form=form,
        )
def myreservation():

    # filter params
    fromDate = request.args.get("fromDate", type=str)
    toDate = request.args.get("toDate", type=str)

    reservations_as_list = UserService.get_customer_reservation(
        fromDate, toDate, current_user.id)
    form = ReservationForm()
    return render_template(
        "user_reservations.html",
        reservations_as_list=reservations_as_list,
        my_date_formatter=my_date_formatter,
        form=form,
    )
def delete_reservation(reservation_id):

    deleted = BookingServices.delete_book(reservation_id, current_user.id)

    reservations_as_list = UserService.get_customer_reservation(
        None, None, current_user.id)
    form = ReservationForm()
    return render_template(
        "user_reservations.html",
        reservations_as_list=reservations_as_list,
        my_date_formatter=my_date_formatter,
        deleted=deleted,
        _test="del_rest_test",
        form=form,
    )
Beispiel #4
0
def restaurant_sheet(restaurant_id):
    """
    Missing refactoring to services
    :param restaurant_id:
    """
    weekDaysLabel = [
        "Monday",
        "Tuesday",
        "Wednesday",
        "Thursday",
        "Friday",
        "Saturday",
        "Sunday",
    ]
    # record = db.session.query(Restaurant).filter_by(id=int(restaurant_id)).all()
    # if record is not None:
    #    record = record[0]

    model = RestaurantServices.get_all_restaurants_info(restaurant_id)
    if model is None:
        abort(501)

    # q_hours = db.session.query(OpeningHours).filter_by(restaurant_id=int(restaurant_id)).all()
    # q_cuisine = db.session.query(Menu).filter_by(restaurant_id=int(restaurant_id)).all()
    # photos = PhotoGallery.query.filter_by(restaurant_id=int(restaurant_id)).all()
    # dishes = db.session.query(MenuDish).filter_by(restaurant_id=restaurant_id).all()

    review_form = ReviewForm()
    book_form = ReservationForm()

    return render_template(
        "restaurantsheet.html",
        weekDaysLabel=weekDaysLabel,
        id=restaurant_id,
        name=model.name,
        lat=model.lat,
        lon=model.lon,
        phone=model.phone,
        covid_measures=model.covid_measures,
        hours=model.opening_hours,
        cuisine=model.cusine,
        photos=model.photos,
        dishes=model.dishes,
        review_form=review_form,
        book_form=book_form,
        reviews=RestaurantServices.get_three_reviews(restaurant_id),
        _test="visit_rest_test",
    )
Beispiel #5
0
def search_restaurant(name_rest):
    current_app.logger.debug(
        "An user want search a restaurant with name {}".format(name_rest))

    file = "index.html"
    if "ROLE" in session and session["ROLE"] == "CUSTOMER":
        file = "index_customer.html"

    form = ReservationForm()
    filter_by_name = RestaurantServices.get_restaurants_by_keyword(
        name=name_rest)
    return render_template(
        file,
        _test="rest_search_test",
        restaurants=filter_by_name,
        search=name_rest,
        form=form,
    )
def index():
    DispatcherMessage.send_message(CALCULATE_RATING_RESTAURANTS, [])
    restaurants = db.session.query(Restaurant).all()
    if current_user is None:
        _test = "anonymous_test"
    else:
        _test = "logged_test"
    if "ROLE" in session:
        if session["ROLE"] == "HEALTH":
            n_positive = db.session.query(Positive).filter_by(
                marked=True).count()
            n_healed = (db.session.query(Positive).filter_by(
                marked=False).distinct(Positive.user_id).count())
            return render_template(
                "index_health.html",
                _test=_test,
                n_positive=n_positive,
                n_healed=n_healed,
            )
        elif session["ROLE"] == "OPERATOR":
            if "RESTAURANT_ID" in session:
                restaurant_id = session["RESTAURANT_ID"]
                model = RestaurantServices.get_all_restaurants_info(
                    restaurant_id)
                if model is None:
                    abort(501)
                weekDaysLabel = [
                    "Monday",
                    "Tuesday",
                    "Wednesday",
                    "Thursday",
                    "Friday",
                    "Saturday",
                    "Sunday",
                ]
                return render_template(
                    "restaurantsheet.html",
                    id=restaurant_id,
                    name=model.name,
                    lat=model.lat,
                    lon=model.lon,
                    phone=model.phone,
                    covid_measures=model.covid_measures,
                    hours=model.opening_hours,
                    cuisine=model.cusine,
                    weekDaysLabel=weekDaysLabel,
                    photos=model.photos,
                    reviews=RestaurantServices.get_three_reviews(
                        restaurant_id),
                    dishes=model.dishes,
                    _test=_test,
                )
            else:
                return render_template("norestaurant.html", _test=_test)
        elif session["ROLE"] == "CUSTOMER":
            form = ReservationForm()
            is_positive = UserService.is_positive(current_user.id)
            return render_template(
                "index_customer.html",
                _test=_test,
                restaurants=restaurants,
                form=form,
                is_positive=is_positive,
            )

    return render_template("index.html", _test=_test, restaurants=restaurants)