Commit 84a1b088 authored by Serge S. Koval's avatar Serge S. Koval

Fixed #73. Added _template_args property which value will be contributed to template when rendering

parent 87566626
from functools import wraps
from re import sub
from flask import Blueprint, render_template, url_for, abort
from flask import Blueprint, render_template, url_for, abort, g
from flask.ext.admin import babel
......@@ -86,6 +86,37 @@ class BaseView(object):
"""
__metaclass__ = AdminViewMeta
@property
def _template_args(self):
"""
Extra template arguments.
If you need to pass some extra parameters to the template,
you can override particular view function, contribute
arguments you want to pass to the template and call parent view.
These arguments are local for this request and will be discarded
in next request.
Any value passed through ``_template_args`` will override whatever
parent view function passed to the template.
For example::
class MyAdmin(ModelView):
@expose('/')
def index(self):
self._template_args['name'] = 'foobar'
self._template_args['code'] = '12345'
super(MyAdmin, self).index()
"""
args = getattr(g, '_admin_template_args', None)
if args is None:
args = g._admin_template_args = dict()
return args
def __init__(self, name=None, category=None, endpoint=None, url=None, static_folder=None):
"""
Constructor.
......@@ -180,6 +211,9 @@ class BaseView(object):
kwargs['_gettext'] = babel.gettext
kwargs['_ngettext'] = babel.ngettext
# Contribute extra arguments
kwargs.update(self._template_args)
return render_template(template, **kwargs)
def _prettify_name(self, name):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment