Merge pull request #8196 from quantopian/jinja-vars-from-config

DEV: Allow supplying jinja vars from python config.
This commit is contained in:
Min RK 2015-04-06 15:09:24 -07:00
commit 3ee98d7557
4 changed files with 14 additions and 1 deletions

View File

@ -120,6 +120,11 @@ class IPythonHandler(AuthenticatedHandler):
else: else:
return app_log return app_log
@property
def jinja_template_vars(self):
"""User-supplied values to supply to jinja templates."""
return self.settings.get('jinja_template_vars', {})
#--------------------------------------------------------------- #---------------------------------------------------------------
# URLs # URLs
#--------------------------------------------------------------- #---------------------------------------------------------------
@ -250,6 +255,7 @@ class IPythonHandler(AuthenticatedHandler):
sys_info=sys_info, sys_info=sys_info,
contents_js_source=self.contents_js_source, contents_js_source=self.contents_js_source,
version_hash=self.version_hash, version_hash=self.version_hash,
**self.jinja_template_vars
) )
def get_json_body(self): def get_json_body(self):

View File

@ -195,6 +195,7 @@ class NotebookWebApplication(web.Application):
config_manager=config_manager, config_manager=config_manager,
# IPython stuff # IPython stuff
jinja_template_vars=ipython_app.jinja_template_vars,
nbextensions_path=ipython_app.nbextensions_path, nbextensions_path=ipython_app.nbextensions_path,
websocket_url=ipython_app.websocket_url, websocket_url=ipython_app.websocket_url,
mathjax_url=ipython_app.mathjax_url, mathjax_url=ipython_app.mathjax_url,
@ -521,6 +522,11 @@ class NotebookApp(BaseIPythonApplication):
jinja_environment_options = Dict(config=True, jinja_environment_options = Dict(config=True,
help="Supply extra arguments that will be passed to Jinja environment.") help="Supply extra arguments that will be passed to Jinja environment.")
jinja_template_vars = Dict(
config=True,
help="Extra variables to supply to jinja templates when rendering.",
)
enable_mathjax = Bool(True, config=True, enable_mathjax = Bool(True, config=True,
help="""Whether to enable MathJax for typesetting math/TeX help="""Whether to enable MathJax for typesetting math/TeX

View File

@ -25,6 +25,7 @@ window.mathjax_url = "{{mathjax_url}}";
{% block params %} {% block params %}
{{super()}}
data-project="{{project}}" data-project="{{project}}"
data-base-url="{{base_url}}" data-base-url="{{base_url}}"
data-ws-url="{{ws_url}}" data-ws-url="{{ws_url}}"

View File

@ -4,7 +4,7 @@
{% block params %} {% block params %}
{{super()}}
data-base-url="{{base_url}}" data-base-url="{{base_url}}"
data-notebook-path="{{notebook_path}}" data-notebook-path="{{notebook_path}}"
data-terminals-available="{{terminals_available}}" data-terminals-available="{{terminals_available}}"