Exemplo n.º 1
0
def search():
    form = SearchForm()
    # Validate the SearchForm
    if form.validate_on_submit():
        # redirect to search function
        query = form.search.data
        return redirect(url_for('get_gifs', query=query))
    return render_template('search.html', form=form)
Exemplo n.º 2
0
def get_gifs(query, offset):

    # If offset is ever set to a negative value set offset to 0
    if int(offset) < 0:
        offset = 0

    form = SearchForm()
    # If there was a search on the results page,
    # validate the form and query the api with the redirect.
    if form.validate_on_submit():
        query = form.search.data
        return redirect(url_for('get_gifs', query=query))
    else:

        # return a list of gif urls to build the results page with.
        gif_links, pagination = GiphyServices.get_gifs(query, offset)

    return render_template('results.html',
                           gif_links=gif_links,
                           form=form,
                           offset=pagination.offset,
                           query=query)