def save_measure(id_op, rest_id):
    """This method gives the operator the possibility to add precaution meausures 
    to his restaurant

    Args:
        id_op (int): univocal identifier of the operator
        rest_id (int): univocal identifier of the restaurant

    Returns:
        Returns the page of the restaurant's details
    """
    measure_form = MeasureForm()
    restaurant = RestaurantManager.retrieve_by_operator_id(id_op)

    if request.method == "POST":
        if measure_form.is_submitted():
            list_measure = restaurant.measures.split(',')
            measure = measure_form.data['measure']
            if measure not in list_measure:
                list_measure.append(measure)
            string = ','.join(list_measure)
            restaurant.set_measures(string)
            RestaurantManager.update_restaurant(restaurant)

    return redirect(url_for('restaurants.details', id_op=id_op))
def my_reservations():
    """Given a restaurant operator, this method returns all its reservations

    """
    restaurant = RestaurantManager.retrieve_by_operator_id(current_user.id)

    if restaurant is None:
        from gooutsafe.views.restaurants import add
        return add(current_user.id)

    return reservation_all(restaurant.id)
def save_avg_stay(id_op, rest_id):
    avg_time_form = StayTimeForm()
    restaurant = RestaurantManager.retrieve_by_operator_id(id_op)

    if request.method == "POST":
        if avg_time_form.validate_on_submit():
            hours = avg_time_form.data['hours']
            minute = avg_time_form.data['minutes']
            minute = (hours * 60) + minute
            restaurant.set_avg_stay(minute)
            RestaurantManager.update_restaurant(restaurant)
        else:
            flash("Insert positive values")

    return redirect(url_for('restaurants.details', id_op=id_op))
Ejemplo n.º 4
0
def delete_user(id_):
    """Deletes the data of the user from the database.

    Args:
        id_ (int): takes the unique id as a parameter

    Returns:
        Redirects the view to the home page
    """
    if current_user.id == id_:
        user = UserManager.retrieve_by_id(id_)
        if user is not None and user.type == "operator":
            restaurant = RestaurantManager.retrieve_by_operator_id(id_)
            if restaurant is not None:
                RestaurantManager.delete_restaurant(restaurant)

        UserManager.delete_user_by_id(id_)
    return redirect(url_for('home.index'))
def details(id_op):
    """Given an operator, this method allows him to see the details of his restaurant

    Args:
        id_op (int): univocal identifier of the operator

    Returns:
        Returns the page of the restaurant's details
    """
    table_form = TableForm()
    time_form = TimesForm()
    measure_form = MeasureForm()
    avg_time_form = StayTimeForm()
    restaurant = RestaurantManager.retrieve_by_operator_id(id_op)

    if restaurant is None:
        return add(current_user.id)
    print("DETAILS OKAY 94-102")
    list_measure = restaurant.measures.split(',')
    tables = TableManager.retrieve_by_restaurant_id(restaurant.id)
    ava = restaurant.availabilities
    avg_stay = restaurant.avg_stay

    if avg_stay is not None:
        h_avg_stay = avg_stay // 60
        m_avg_stay = avg_stay - (h_avg_stay * 60)
        avg_stay = "%dH:%dM" % (h_avg_stay, m_avg_stay)
    else:
        avg_stay = 0

    return render_template('add_restaurant_details.html',
                           restaurant=restaurant,
                           tables=tables,
                           table_form=table_form,
                           time_form=time_form,
                           times=ava,
                           measure_form=measure_form,
                           avg_time_form=avg_time_form,
                           avg_stay=avg_stay,
                           list_measure=list_measure[1:])
def save_details(id_op, rest_id):
    """This method gives the operator the possibility to add tables to his restaurant

    Args:
        id_op (int): univocal identifier of the operator
        rest_id (int): univocal identifier of the restaurant

    Returns:
        Returns the page of the restaurant's details
    """
    table_form = TableForm()
    restaurant = RestaurantManager.retrieve_by_operator_id(id_op)

    if request.method == "POST":
        if table_form.is_submitted():
            num_tables = table_form.data['number']
            capacity = table_form.data['max_capacity']

            for i in range(0, num_tables):
                if capacity >= 1:
                    table = Table(capacity=capacity, restaurant=restaurant)
                    TableManager.create_table(table)

    return redirect(url_for('restaurants.details', id_op=id_op))