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
1766909e
Commit
1766909e
authored
Mar 24, 2016
by
michael lynch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding tests to see why the PR failed.
parent
7d36dde6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
17 deletions
+41
-17
base.py
flask_admin/base.py
+22
-17
test_base.py
flask_admin/tests/test_base.py
+19
-0
No files found.
flask_admin/base.py
View file @
1766909e
...
@@ -518,7 +518,7 @@ class Admin(object):
...
@@ -518,7 +518,7 @@ class Admin(object):
self
.
template_mode
=
template_mode
or
'bootstrap2'
self
.
template_mode
=
template_mode
or
'bootstrap2'
self
.
category_icon_classes
=
category_icon_classes
or
dict
()
self
.
category_icon_classes
=
category_icon_classes
or
dict
()
# Add
predefined
index view
# Add index view
self
.
_set_admin_index_view
(
index_view
=
index_view
,
endpoint
=
endpoint
,
url
=
url
)
self
.
_set_admin_index_view
(
index_view
=
index_view
,
endpoint
=
endpoint
,
url
=
url
)
# Register with application
# Register with application
...
@@ -541,25 +541,29 @@ class Admin(object):
...
@@ -541,25 +541,29 @@ class Admin(object):
self
.
_add_view_to_menu
(
view
)
self
.
_add_view_to_menu
(
view
)
def
_set_admin_index_view
(
self
,
index_view
=
None
,
def
_set_admin_index_view
(
self
,
index_view
=
None
,
endpoint
=
None
,
url
=
None
):
endpoint
=
None
,
url
=
None
):
"""
"""
Add the admin index view.
Add the admin index view.
:param index_view:
:param index_view:
Home page view to use. Defaults to `AdminIndexView`.
Home page view to use. Defaults to `AdminIndexView`.
:param url:
:param url:
Base URL
Base URL
:param endpoint:
:param endpoint:
Base endpoint name for index view. If you use multiple instances of the `Admin` class with
Base endpoint name for index view. If you use multiple instances of the `Admin` class with
a single Flask application, you have to set a unique endpoint name for each instance.
a single Flask application, you have to set a unique endpoint name for each instance.
"""
"""
self
.
index_view
=
index_view
or
AdminIndexView
(
endpoint
=
endpoint
,
url
=
url
)
self
.
index_view
=
index_view
or
AdminIndexView
(
endpoint
=
endpoint
,
url
=
url
)
self
.
endpoint
=
endpoint
or
self
.
index_view
.
endpoint
self
.
endpoint
=
endpoint
or
self
.
index_view
.
endpoint
self
.
url
=
url
or
self
.
index_view
.
url
self
.
url
=
url
or
self
.
index_view
.
url
# Add predefined index view
# Add predefined index view
self
.
add_view
(
self
.
index_view
)
# assume index view is always the first element of views.
if
len
(
self
.
_views
)
>
0
:
self
.
_views
[
0
]
=
self
.
index_view
else
:
self
.
add_view
(
self
.
index_view
)
def
add_views
(
self
,
*
args
):
def
add_views
(
self
,
*
args
):
"""
"""
...
@@ -659,12 +663,13 @@ class Admin(object):
...
@@ -659,12 +663,13 @@ class Admin(object):
self
.
_init_extension
()
self
.
_init_extension
()
# Register Index view
self
.
_set_admin_index_view
(
index_view
=
index_view
,
endpoint
=
endpoint
,
url
=
url
)
# Register views
# Register views
for
view
in
self
.
_views
:
for
view
in
self
.
_views
:
app
.
register_blueprint
(
view
.
create_blueprint
(
self
))
app
.
register_blueprint
(
view
.
create_blueprint
(
self
))
# Register Index view
self
.
_set_admin_index_view
(
index_view
=
index_view
,
endpoint
=
endpoint
,
url
=
url
)
def
_init_extension
(
self
):
def
_init_extension
(
self
):
if
not
hasattr
(
self
.
app
,
'extensions'
):
if
not
hasattr
(
self
.
app
,
'extensions'
):
...
...
flask_admin/tests/test_base.py
View file @
1766909e
...
@@ -114,6 +114,25 @@ def test_custom_index_view():
...
@@ -114,6 +114,25 @@ def test_custom_index_view():
eq_
(
admin
.
_views
[
0
],
view
)
eq_
(
admin
.
_views
[
0
],
view
)
def
test_custom_index_view_in_init_app
():
view
=
base
.
AdminIndexView
(
name
=
'a'
,
category
=
'b'
,
endpoint
=
'c'
,
url
=
'/d'
,
template
=
'e'
)
app
=
Flask
(
__name__
)
admin
=
base
.
Admin
()
admin
.
init_app
(
app
,
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
)
...
...
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