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
55e5fb93
Commit
55e5fb93
authored
Jun 03, 2015
by
Serge S. Koval
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ability to override automatically generated endpoint name
parent
86d0170a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
23 deletions
+38
-23
base.py
flask_admin/base.py
+16
-12
base.py
flask_admin/model/base.py
+9
-7
test_base.py
flask_admin/tests/test_base.py
+13
-4
No files found.
flask_admin/base.py
View file @
55e5fb93
...
...
@@ -187,7 +187,7 @@ class BaseView(with_metaclass(AdminViewMeta, BaseViewClass)):
"""
self
.
name
=
name
self
.
category
=
category
self
.
endpoint
=
endpoint
self
.
endpoint
=
self
.
_get_endpoint
(
endpoint
)
self
.
url
=
url
self
.
static_folder
=
static_folder
self
.
static_url_path
=
static_url_path
...
...
@@ -205,6 +205,16 @@ class BaseView(with_metaclass(AdminViewMeta, BaseViewClass)):
if
self
.
_default_view
is
None
:
raise
Exception
(
u'Attempted to instantiate admin view
%
s without default view'
%
self
.
__class__
.
__name__
)
def
_get_endpoint
(
self
,
endpoint
):
"""
Generate Flask endpoint name. By default converts class name to lower case if endpoint is
not explicitly provided.
"""
if
endpoint
:
return
endpoint
return
self
.
__class__
.
__name__
.
lower
()
def
create_blueprint
(
self
,
admin
):
"""
Create Flask blueprint.
...
...
@@ -212,10 +222,6 @@ class BaseView(with_metaclass(AdminViewMeta, BaseViewClass)):
# Store admin instance
self
.
admin
=
admin
# If endpoint name is not provided, get it from the class name
if
self
.
endpoint
is
None
:
self
.
endpoint
=
self
.
__class__
.
__name__
.
lower
()
# If the static_url_path is not provided, use the admin's
if
not
self
.
static_url_path
:
self
.
static_url_path
=
admin
.
static_url_path
...
...
@@ -233,15 +239,13 @@ class BaseView(with_metaclass(AdminViewMeta, BaseViewClass)):
if
not
self
.
url
.
startswith
(
'/'
):
self
.
url
=
'
%
s/
%
s'
%
(
self
.
admin
.
url
,
self
.
url
)
# If we're working from the root of the site, set prefix to None
if
self
.
url
==
'/'
:
self
.
url
=
None
# prevent admin static files from conflicting with flask static files
if
not
self
.
static_url_path
:
self
.
static_folder
=
'static'
self
.
static_url_path
=
'/static/admin'
self
.
static_folder
=
'static'
self
.
static_url_path
=
'/static/admin'
# If name is not povided, use capitalized endpoint name
if
self
.
name
is
None
:
...
...
flask_admin/model/base.py
View file @
55e5fb93
...
...
@@ -561,28 +561,30 @@ class BaseModelView(BaseView, ActionsMixin):
:param menu_icon_value:
Icon glyph name or URL, depending on `menu_icon_type` setting
"""
self
.
model
=
model
# If name not provided, it is model name
if
name
is
None
:
name
=
'
%
s'
%
self
.
_prettify_class_name
(
model
.
__name__
)
# If endpoint not provided, it is model name
if
endpoint
is
None
:
endpoint
=
model
.
__name__
.
lower
()
super
(
BaseModelView
,
self
)
.
__init__
(
name
,
category
,
endpoint
,
url
,
static_folder
,
menu_class_name
=
menu_class_name
,
menu_icon_type
=
menu_icon_type
,
menu_icon_value
=
menu_icon_value
)
self
.
model
=
model
# Actions
self
.
init_actions
()
# Scaffolding
self
.
_refresh_cache
()
# Endpoint
def
_get_endpoint
(
self
,
endpoint
):
if
endpoint
:
return
super
(
BaseModelView
,
self
)
.
_get_endpoint
(
endpoint
)
return
self
.
__class__
.
__name__
.
lower
()
# Caching
def
_refresh_forms_cache
(
self
):
# Forms
...
...
flask_admin/tests/test_base.py
View file @
55e5fb93
...
...
@@ -76,7 +76,7 @@ def test_baseview_defaults():
view
=
MockView
()
eq_
(
view
.
name
,
None
)
eq_
(
view
.
category
,
None
)
eq_
(
view
.
endpoint
,
None
)
eq_
(
view
.
endpoint
,
'mockview'
)
eq_
(
view
.
url
,
None
)
eq_
(
view
.
static_folder
,
None
)
eq_
(
view
.
admin
,
None
)
...
...
@@ -388,3 +388,12 @@ def test_menu_links():
def
check_class_name
():
view
=
MockView
()
eq_
(
view
.
name
,
'Mock View'
)
def
check_endpoint
():
class
CustomView
(
MockView
):
def
_get_endpoint
(
self
,
endpoint
):
return
'admin.'
+
super
(
CustomView
,
self
)
.
_get_endpoint
(
endpoint
)
view
=
CustomView
()
eq_
(
view
.
endpoint
,
'admin.customview'
)
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