Ejemplo n.º 1
0
def home():
    searchform = SearchForm()
    all_hostels = Hostel.query.all()
    if searchform.validate_on_submit():
        query = searchform.search_input.data
        return redirect(url_for('search_results', query=query))
    for hostels in all_hostels:
        single = get_name(hostels)
    return render_template("home.html",
                           title='Home',
                           searchform=SearchForm(),
                           current_user=current_user,
                           hostels=all_hostels,
                           l_about='Description',
                           c_about='Description',
                           a_about='Description')
Ejemplo n.º 2
0
def search_results(query):
    searchform = SearchForm()
    # Have a 404 page saying that Hostel not found
    if searchform.validate_on_submit():
        query = searchform.search_input.data
        return redirect(url_for('search_results', query=query))
    Query = query.capitalize()
    query_name = Query.replace(" ", "_") if " " in Query else Query
    results = Hostel.query.filter_by(name=query_name).first_or_404()

    results.name = results.name.replace(
        "_", " ") if results else "No Hostel was found with that name."

    return render_template('search_results.html',
                           title=f'Search results for {query}',
                           results=results,
                           searchform=searchform)
Ejemplo n.º 3
0
def search():
    form = SearchForm()
    if request.method == 'POST' and form.validate_on_submit():
        return redirect((url_for('main.result', text=form.search.data)))
    return render_template('search.html', form=form)