Commit c4a63e75 authored by Serge S. Koval's avatar Serge S. Koval

Merge branch 'master' of github.com:mrjoes/flask-admin

parents ace9aaac 3336689a
......@@ -89,7 +89,7 @@ Now, lets add an administrative view. To do this, you need to derive from :class
If you will run this example, you will see that menu has two items: Home and Hello.
Each view class should have default page - view method with '/' url. Following code won't work::
Each view class should have default page-view method with '/' url. Following code won't work::
class MyView(BaseView):
@expose('/index/')
......
......@@ -264,7 +264,8 @@ class AdminIndexView(BaseView):
class MyHomeView(AdminIndexView):
@expose('/')
def index(self):
return render_template('adminhome.html')
arg1 = 'Hello'
return render_template('adminhome.html', arg1=arg1)
admin = Admin(index_view=MyHomeView())
......@@ -274,17 +275,21 @@ class AdminIndexView(BaseView):
* If endpoint is not provided, will use ``admin``
* Default URL route is ``/admin``.
* 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'),
category,
endpoint or 'admin',
url or '/admin',
'static')
self._template = template
@expose()
def index(self):
return self.render('admin/index.html')
return self.render(self._template)
class MenuItem(object):
......@@ -463,9 +468,6 @@ class Admin(object):
:param app:
Flask application instance
"""
if self.app is not None:
raise Exception('Flask-Admin is already associated with an application.')
self.app = app
self._init_extension()
......
......@@ -31,7 +31,18 @@ def bool_formatter(value):
return Markup('<i class="icon-ok"></i>' if value else '')
def list_formatter(values):
"""
Return string with comma separated values
:param values:
Value to check
"""
return u', '.join(values)
DEFAULT_FORMATTERS = {
type(None): empty_formatter,
bool: bool_formatter
bool: bool_formatter,
list: list_formatter,
}
......@@ -45,14 +45,33 @@ def test_base_defaults():
admin = base.Admin()
eq_(admin.name, 'Admin')
eq_(admin.url, '/admin')
eq_(admin.endpoint, 'admin')
eq_(admin.app, None)
ok_(admin.index_view is not None)
eq_(admin.index_view._template, 'admin/index.html')
# Check if default view was added
eq_(len(admin._views), 1)
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():
app = Flask(__name__)
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