def my_profile():
    """This method allows the customer to see its personal page

    Returns:
        Redirects the view to personal page of the customer
    """
    reservations = ReservationManager.retrieve_by_customer_id(current_user.id)
    form = ReservationForm()
    social_form = AddSocialNumberForm()
    customer = CustomerManager.retrieve_by_id(current_user.id)
    restaurants = RestaurantManager.retrieve_all()

    return render_template('customer_profile.html', customer=customer,
                           reservations=reservations, restaurants=restaurants, 
                           form=form, social_form=social_form)
def profile(id):
    """This method allows the customer to see its personal page

    Args:
        id (int): univocal identifier of the customer

    Returns:
        Redirects the view to personal page of the customer
    """
    if current_user.id == id:
        reservations = ReservationManager.retrieve_by_customer_id(id)
        form = ReservationForm()
        social_form = AddSocialNumberForm()
        customer = CustomerManager.retrieve_by_id(id)
        restaurants = RestaurantManager.retrieve_all()
        return render_template('customer_profile.html', customer=customer,
                               reservations=reservations, restaurants=restaurants, 
                               form=form, social_form=social_form)

    return redirect(url_for('home.index'))
Exemple #3
0
def search():
    """This method allows customers to search restaurants, using a search bar.
    It's possible to retrieve restaurants based on their name, city or cuisine's type.

    """
    form = RestaurantSearchForm()

    keyword = request.args.get('keyword', default=None, type=str)
    filters = request.args.get('filters', default=None, type=str)

    keyword = None if keyword is None or len(keyword) == 0 else keyword
    json_list = []
    if keyword is not None and filters is None:
        restaurants = search_by(keyword, form.DEFAULT_SEARCH_FILTER)
    elif keyword is not None and filters is not None:
        restaurants = search_by(keyword, filters)
    else:
        restaurants = RestaurantManager.retrieve_all()
        for r in restaurants:
            json_list.append({"name": r.name, "lat": r.lat, "lon": r.lon })
        json_list = json.dumps(json_list)

    return render_template('explore.html', search_form=form, restaurants=restaurants, json_res=json_list)