예제 #1
0
def search_results():
    """
    Search form input.

    Pass user input strings to birdsearch. Also pass the user's ID if the user is logged in.
    Use the results from birdsearch to rerender the homepage.
    """
    
    spuh = SPUH_EQUIVALENTS
    # get the user's id
    this_user_id = session.get('user_id')

    # get the user's search variables
    bird_limit_param = request.form.get("which_birds")
    spuh_param = request.form.get("select_spuh")
    order_param = request.form.get("select_order")
    family_param = request.form.get("select_family")
    region_param = request.form.get("select_region")
    other_param = request.form.get("fuzzy")

    # pass everything to birdsearch, which returns a dictionary
    bird_dict = birdsearch(this_user_id = this_user_id,
                           bird_limit = bird_limit_param,
                           spuh = spuh_param, 
                           order = order_param, 
                           family = family_param,
                           region = region_param)


    # use the birdsearch dictionary to render the home page
    return render_template("homepage_new.html", birds_nest=bird_dict["birds_dict"], orders=bird_dict["orders"], all_taxons = bird_dict["all_taxons"], spuh=spuh)
예제 #2
0
파일: server.py 프로젝트: dovekie/Lek_app
def index():
    """
    Display the home page with a dynamic list of bird species organized by order and family.

    Gets userid from the session variable and checks for a default search string.
    If a default exists, fetches it and customizes the data displayed on the page.
    """
    # get the list of spuh
    spuh = SPUH_EQUIVALENTS

    # if the user is logged in, this will return their ID
    this_user_id = session.get('user_id', None)
    if this_user_id == 9:
        session["new_user"] = True                        

    # If the user is not logged in, call birdsearch with no arguments
    # Display the default: all birds.
    # If the user is logged in, fetch their default search from the database
    # Display their custom page
    if this_user_id is None:
        print "Homepage rendering with no user default: User not logged in."
        session.clear()
        bird_dict = birdsearch()
    else:
        # Database query
        user_default = UserSearch.query.filter(UserSearch.user_id == this_user_id, 
                                                   UserSearch.user_default == True).first()
        if user_default:
            # Split the serialized search string on & to get paramater/value pairs in strings
            param_list = user_default.search_string.split("&")
            # Create a dictionary by splitting those pairs on =
            search_dict = {param.split("=")[0]: param.split("=")[1] for param in param_list}
            
            print "user default search>>>", search_dict
            # Call birdsearch with the user's custom search parameters
            bird_dict = birdsearch(this_user_id, 
                                  search_dict["which_birds"], 
                                  search_dict["select_spuh"], 
                                  search_dict["select_order"], 
                                  search_dict["select_family"], 
                                  search_dict["select_region"])
        # otherwise, show the generic page                                                           
        else:
            print "Homepage rendering with no user default: User has no default set"
            bird_dict = birdsearch()

    return render_template("homepage.html", birds_nest=bird_dict["birds_dict"], orders=bird_dict["orders"], spuh=spuh)
예제 #3
0
def show_all():
    """
    Show all bird with one button click
    """

    spuh = SPUH_EQUIVALENTS
    # Call birdsearch with no arguments.
    bird_dict = birdsearch()
    return render_template("homepage_new.html", birds_nest=bird_dict["birds_dict"], orders=bird_dict["orders"], all_taxons = bird_dict["all_taxons"], spuh=spuh)
예제 #4
0
def more_birds():
    offset = int(request.args.get('scroll_counter')) * 50
    print offset

    bird_dict = birdsearch(offset = offset)
    send_back = dumps({'birds_nest': bird_dict["birds_dict"], 'orders': bird_dict["orders"], 'all_taxons': bird_dict["all_taxons"]})

    #send_back = dumps({'offset': offset, 'statement': "it worked!"})

    return send_back
예제 #5
0
def search():
    """
    This displays the search form. It takes no arguments.

    This route uses variables imported from another file.
    """
    # get the SPUH and REGION dictionaries
    spuh = SPUH_EQUIVALENTS
    regions = REGION_CODES

    # Call birdsearch with no arguments to return all birds.
    bird_dict = birdsearch()                                                                             

    return render_template("search.html", orders=bird_dict["orders"], birds_nest = bird_dict["birds_dict"], regions=regions, spuh=spuh)
예제 #6
0
def lifelist():
    """
    Display all birds that the user has marked as 'seen'

    Only logged-in users should see this page.
    """

    spuh = SPUH_EQUIVALENTS
    user_id = session.get('user_id', None)
    print "lifelist user id:", user_id    

    # Call birdsearch with this user's ID and the parameter that shows their birds only.
    bird_dict = birdsearch(this_user_id=user_id, bird_limit = "my_birds")

    return render_template("homepage_new.html", birds_nest=bird_dict["birds_dict"], orders=bird_dict["orders"], all_taxons = bird_dict["all_taxons"], spuh=spuh)