Example #1
0
def tours(current_page):
    tour_form = TourForm()

    if not tours_blueprint.current_items_per_page:
        tours_blueprint.current_items_per_page = \
            tour_form.tours_per_page.default

    if not tours_blueprint.current_order_by:
        tours_blueprint.current_order_by = tour_form.order_by.default

    if tour_form.validate_on_submit():
        tours_blueprint.current_items_per_page = tour_form.tours_per_page.data
        tours_blueprint.current_order_by = tour_form.order_by.data
        return redirect(url_for('tours.tours_default'))

    pagination = TourDAO.get_page_of_tours(
        current_page, tours_blueprint.current_items_per_page,
        tours_blueprint.current_order_by)

    app_tours = []
    if current_user.is_authenticated:
        rows = RegistrationDAO.get_registrations_tour_ids_of_user(current_user)
        app_tours = [x[0] for x in rows]

    return render_template('tours.html',
                           tour_form=tour_form,
                           tours=pagination.items,
                           pagination=pagination,
                           items=tours_blueprint.current_items_per_page,
                           sort=tours_blueprint.current_order_by,
                           apply_tours=app_tours)