Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
flask-admin
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Python-Dev
flask-admin
Commits
9db8c9e5
Commit
9db8c9e5
authored
Aug 31, 2015
by
Serge S. Koval
Browse files
Options
Browse Files
Download
Plain Diff
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
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
0 deletions
+55
-0
base.py
flask_admin/base.py
+32
-0
test_base.py
flask_admin/tests/test_base.py
+23
-0
No files found.
flask_admin/base.py
View file @
9db8c9e5
...
...
@@ -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
)
...
...
flask_admin/tests/test_base.py
View file @
9db8c9e5
...
...
@@ -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'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment