Commit 9db8c9e5 authored by Serge S. Koval's avatar Serge S. Koval

Merge pull request #1032 from pawl/add_all

add a way to add multiple views or links with a single line of code
parents f9583efc 7e4ed07c
......@@ -540,6 +540,22 @@ class Admin(object):
self._add_view_to_menu(view)
def add_views(self, *args):
"""
Add one or more views to the collection.
Examples::
admin.add_views(view1)
admin.add_views(view1, view2, view3, view4)
admin.add_views(*my_list)
:param args:
Argument list including the views to add.
"""
for view in args:
self.add_view(view)
def add_link(self, link):
"""
Add link to menu links collection.
......@@ -552,6 +568,22 @@ class Admin(object):
else:
self._menu_links.append(link)
def add_links(self, *args):
"""
Add one or more links to the menu links collection.
Examples::
admin.add_links(link1)
admin.add_links(link1, link2, link3, link4)
admin.add_links(*my_list)
:param args:
Argument list including the links to add.
"""
for link in args:
self.add_link(link)
def _add_menu_item(self, menu_item, target_category):
if target_category:
cat_text = as_unicode(target_category)
......
......@@ -195,6 +195,15 @@ def test_baseview_urls():
eq_(len(view._urls), 2)
def test_add_views():
app = Flask(__name__)
admin = base.Admin(app)
admin.add_views(MockView(endpoint='test1'), MockView(endpoint='test2'))
eq_(len(admin.menu()), 3)
@raises(Exception)
def test_no_default():
app = Flask(__name__)
......@@ -385,6 +394,20 @@ def test_menu_links():
ok_('TestMenuLink2' in data)
def test_add_links():
app = Flask(__name__)
admin = base.Admin(app)
admin.add_links(base.MenuLink('TestMenuLink1', endpoint='.index'),
base.MenuLink('TestMenuLink2', url='http://python.org/'))
client = app.test_client()
rv = client.get('/admin/')
data = rv.data.decode('utf-8')
ok_('TestMenuLink1' in data)
ok_('TestMenuLink2' in data)
def check_class_name():
view = MockView()
eq_(view.name, 'Mock View')
......
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