예제 #1
0
파일: app.py 프로젝트: kdubbs0/CMSC388J-s20
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)
예제 #2
0
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)
예제 #3
0
def test_index(client):
    resp = client.get("/")
    assert resp.status_code == 200
    search = SimpleNamespace(search_query="guardians", submit="Search")
    form = SearchForm(formdata=None, obj=search)
    response = client.post("/", data=form.data, follow_redirects=True)
    assert b"Guardians of the Galaxy" in response.data
예제 #4
0
def test_search_input_validation(client, query, message):
    resp = client.get("/")
    assert resp.status_code == 200

    search = SimpleNamespace(search_query=query, submit="Search")
    form = SearchForm(formdata=None, obj=search)
    response = client.post("/", data=form.data, follow_redirects=True)

    assert message in response.data
예제 #5
0
def test_search_input_validation(client, query, message):
    '''
    Test that with an empty query, you get the error "This field is required."
    Test that with a very short string, you get the error "Too many results"
    Test that with some gibberish (maybe a random string?) you get the error "Movie not found"
    Test that with a string that's too long, you get the error "Field must be between 1 and 100 characters long."
    '''
    search = SimpleNamespace(search_query=query, submit="Search")
    form = SearchForm(formdata=None, obj=search)
    response = client.post("/", data=form.data, follow_redirects=True)
    assert message in response.data
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'))