Exemple #1
0
def index():
    form = SearchForm()

    if form.validate_on_submit():
        return redirect(url_for('query_results', query=form.search_query.data))

    return render_template('index.html', form=form)
def index():
    form = SearchForm()
    print('FELL INTO VIEW', file=sys.stdout)
    if form.validate_on_submit():
        # return redirect(url_for('query_results', query=form.search_query.data))
        print('FELL INTO VALIDATE FORM', file=sys.stdout)
        return redirect(
            url_for('features.query_results', query=form.search_query.data))
    return render_template('index.html', form=form)
def search():
    if current_user.is_authenticated:
        form = SearchForm()

        if form.validate_on_submit():
            start_time = datetime.now()
            searched_tokens = form.search_field.data.lower()
            """extract search results"""
            search_handler = SearchHandler(searched_token=searched_tokens)
            list_of_qualified_movies_obj = search_handler.extract_qualified_movies(
            )

            current_user_id = current_user.id
            user_library_handler = UserLibraryHandler(user_id=current_user_id)
            """get dict of movie_id(int) : in library(bool)"""
            dict_of_movie_id_in_library = user_library_handler.get_dict_of_movie_id_in_library(
                list_of_movies_obj=list_of_qualified_movies_obj)

            "process for checked boxes and unchecked movies"
            if request.form.get('apply_changes'):
                list_of_checked = request.form.getlist('add_to_library')
                list_of_checked = list(map(int, list_of_checked))
                user_library_handler.update_user_library(
                    list_of_checked_boxes=list_of_checked)

            end_time = datetime.now()
            return render_template(
                'search.html',
                title='Search results',
                form=form,
                results=list_of_qualified_movies_obj,
                time_taken=end_time - start_time,
                dict_movies_lib=dict_of_movie_id_in_library,
                tmdb_base_url=app.config['TMDB_BASE_PATH_URL'])

        return render_template('search.html', title='Search movies', form=form)

    return redirect(url_for('login'))