def edit_restaurant(id_op, rest_id): """This method allows the operator to edit the information about 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 """ form = RestaurantForm() restaurant = RestaurantManager.retrieve_by_id(rest_id) if request.method == "POST": if form.is_submitted(): name = form.data['name'] restaurant.set_name(name) address = form.data['address'] restaurant.set_address(address) city = form.data['city'] restaurant.set_city(city) phone = form.data['phone'] restaurant.set_phone(phone) menu_type = form.data['menu_type'] restaurant.set_menu_type(menu_type) RestaurantManager.update_restaurant(restaurant) return redirect(url_for('auth.operator', id=id_op)) return render_template('update_restaurant.html', form=form)
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 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))