Commit 3336689a authored by Serge S. Koval's avatar Serge S. Koval

Merge pull request #111 from Koblaid/AdminIndexView_add_template_parameter

Added parameter 'template' to AdminIndexView.__init__()
parents 08bb9cab e01deb7f
...@@ -264,7 +264,8 @@ class AdminIndexView(BaseView): ...@@ -264,7 +264,8 @@ class AdminIndexView(BaseView):
class MyHomeView(AdminIndexView): class MyHomeView(AdminIndexView):
@expose('/') @expose('/')
def index(self): def index(self):
return render_template('adminhome.html') arg1 = 'Hello'
return render_template('adminhome.html', arg1=arg1)
admin = Admin(index_view=MyHomeView()) admin = Admin(index_view=MyHomeView())
...@@ -274,17 +275,21 @@ class AdminIndexView(BaseView): ...@@ -274,17 +275,21 @@ class AdminIndexView(BaseView):
* If endpoint is not provided, will use ``admin`` * If endpoint is not provided, will use ``admin``
* Default URL route is ``/admin``. * Default URL route is ``/admin``.
* Automatically associates with static folder. * Automatically associates with static folder.
* Default template is ``admin/index.html``
""" """
def __init__(self, name=None, category=None, endpoint=None, url=None): def __init__(self, name=None, category=None,
endpoint=None, url=None,
template='admin/index.html'):
super(AdminIndexView, self).__init__(name or babel.lazy_gettext('Home'), super(AdminIndexView, self).__init__(name or babel.lazy_gettext('Home'),
category, category,
endpoint or 'admin', endpoint or 'admin',
url or '/admin', url or '/admin',
'static') 'static')
self._template = template
@expose() @expose()
def index(self): def index(self):
return self.render('admin/index.html') return self.render(self._template)
class MenuItem(object): class MenuItem(object):
......
...@@ -45,14 +45,33 @@ def test_base_defaults(): ...@@ -45,14 +45,33 @@ def test_base_defaults():
admin = base.Admin() admin = base.Admin()
eq_(admin.name, 'Admin') eq_(admin.name, 'Admin')
eq_(admin.url, '/admin') eq_(admin.url, '/admin')
eq_(admin.endpoint, 'admin')
eq_(admin.app, None) eq_(admin.app, None)
ok_(admin.index_view is not None) ok_(admin.index_view is not None)
eq_(admin.index_view._template, 'admin/index.html')
# Check if default view was added # Check if default view was added
eq_(len(admin._views), 1) eq_(len(admin._views), 1)
eq_(admin._views[0], admin.index_view) eq_(admin._views[0], admin.index_view)
def test_custom_index_view():
view = base.AdminIndexView(name='a', category='b', endpoint='c',
url='/d', template='e')
admin = base.Admin(index_view=view)
eq_(admin.endpoint, 'c')
eq_(admin.url, '/d')
ok_(admin.index_view is view)
eq_(view.name, 'a')
eq_(view.category, 'b')
eq_(view._template, 'e')
# Check if view was added
eq_(len(admin._views), 1)
eq_(admin._views[0], view)
def test_base_registration(): def test_base_registration():
app = Flask(__name__) app = Flask(__name__)
admin = base.Admin(app) admin = base.Admin(app)
......
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