Fill in notebook context with default values.

def prepare_notebook_context(request, notebook_context):
    """Fill in notebook context with default values."""

    if not notebook_context:
        notebook_context = {}

    # Override notebook Jinja templates
    if "extra_template_paths" not in notebook_context:
        notebook_context["extra_template_paths"] = [os.path.join(os.path.dirname(__file__), "server", "templates")]

    # Furious invalid state follows if we let this slip through
    assert type(notebook_context["extra_template_paths"]) == list, "Got bad extra_template_paths {}".format(notebook_context["extra_template_paths"])

    # Jinja variables
    notebook_context["jinja_environment_options"] = notebook_context.get("jinja_environment_options", {})

    assert type(notebook_context["jinja_environment_options"]) == dict

    # XXX: Following passing of global variables to Jinja templates requires Jinja 2.8.0dev+ version and is not yet supported
    # http://jinja.pocoo.org/docs/dev/api/#jinja2.Environment.globals

    # notebook_context["jinja_environment_options"]["globals"] = notebook_context["jinja_environment_options"].get("globals", {})
    # globals_ = notebook_context["jinja_environment_options"]["globals"]
    #
    # assert type(globals_) == dict
    #
    # if not "home_url" in globals_:
    #     globals_["home_url"] = request.host_url
    #
    # if not "home_title" in globals_:
    #     globals_["home_title"] = "Back to site"

    # Tell notebook to correctly address WebSockets allow origin policy
    notebook_context["allow_origin"] = route_to_alt_domain(request, request.host_url)
    notebook_context["notebook_path"] = request.route_path("notebook_proxy", remainder="")

    # Record the hash of the current parameters, so we know if this user accesses the notebook in this or different context
    if "context_hash" not in notebook_context:
        notebook_context["context_hash"] = make_dict_hash(notebook_context)

    print(notebook_context)