コード例 #1
0
def get_employee_details():
    """Process search and return the employee details page."""

    # Get employee name from search form (passed in the request object)
    name = request.args.get("employee_name")

    # If the user didn't type anything, ask them to.
    if not name:
        flash("Please type in a first name.")

    # If the name isn't in our directory, flash a message to the user.
    elif name.lower() not in employee_directory:
        flash("{{name}} not found.".format(name=name))

    # We have a name, and it's in our directory. Return that info.
    else:
        employee_info = employee_directory.get(name.lower())
        return render_template("employee_details.html", details=employee_info)

    # If we didn't return the employee details page, send the user back to the
    # page they were on before.
    return (redirect(request.referrer))
コード例 #2
0
def get_employee_details():
    """this is the 'action' we use for our searches. It returns the employee details page """

    # get the employee name from the search form (which is passed in the request object):
    name = request.args.get("employee_name")

    # if the user doesn't type in anything:
    if not name:
        flash("please type in a first name")

    # if the name isn't in our directory:
    elif name.lower() not in employee_directory:
        # 'flash' a message to the user so they see it once.
        flash("%s not found." % name)

    # we have a name, its in our directory, so let's return that info:
    else:
        employee_info = employee_directory.get(name.lower())
        return render_template("employee_details.html", details=employee_info)

    # if we didn't return the employee details page, send them back to the page
    # they were on before:
    return(redirect(request.referrer))
コード例 #3
0
def get_employee_details():
    """this is the 'action' we use for our searches. It returns the employee details page """

    # get the employee name from the search form (which is passed in the request object):
    name = request.args.get("employee_name")

    # if the user doesn't type in anything:
    if not name:
        flash("please type in a first name")

    # if the name isn't in our directory:
    elif name.lower() not in employee_directory:
        # 'flash' a message to the user so they see it once.
        flash("%s not found." % name)

    # we have a name, its in our directory, so let's return that info:
    else:
        employee_info = employee_directory.get(name.lower())
        return render_template("employee_details.html", details=employee_info)

    # if we didn't return the employee details page, send them back to the page
    # they were on before:
    return(redirect(request.referrer))