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
4466d365
Commit
4466d365
authored
Dec 28, 2013
by
Serge S. Koval
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed #424. Fixed automatic class name generation
parent
19ca645c
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
32 additions
and
8 deletions
+32
-8
base.py
flask_admin/base.py
+4
-5
tools.py
flask_admin/contrib/sqla/tools.py
+1
-0
helpers.py
flask_admin/helpers.py
+11
-0
base.py
flask_admin/model/base.py
+3
-3
test_base.py
flask_admin/tests/test_base.py
+5
-0
test_model.py
flask_admin/tests/test_model.py
+8
-0
No files found.
flask_admin/base.py
View file @
4466d365
from
functools
import
wraps
from
re
import
sub
from
flask
import
Blueprint
,
render_template
,
url_for
,
abort
,
g
from
flask.ext.admin
import
babel
...
...
@@ -211,7 +210,7 @@ class BaseView(with_metaclass(AdminViewMeta, BaseViewClass)):
# If name is not povided, use capitalized endpoint name
if
self
.
name
is
None
:
self
.
name
=
self
.
_prettify_name
(
self
.
__class__
.
__name__
)
self
.
name
=
self
.
_prettify_
class_
name
(
self
.
__class__
.
__name__
)
# Create blueprint and register rules
self
.
blueprint
=
Blueprint
(
self
.
endpoint
,
__name__
,
...
...
@@ -253,14 +252,14 @@ class BaseView(with_metaclass(AdminViewMeta, BaseViewClass)):
return
render_template
(
template
,
**
kwargs
)
def
_prettify_name
(
self
,
name
):
def
_prettify_
class_
name
(
self
,
name
):
"""
Prettify a class name by splitting the name on capitalized characters. So, 'MySuperClass' becomes 'My Super Class'
Split words in PascalCase string into separate words.
:param name:
String to prettify
"""
return
sub
(
r'(?<=.)([A-Z])'
,
r' \1'
,
name
)
return
h
.
prettify_class_name
(
name
)
def
is_visible
(
self
):
"""
...
...
flask_admin/contrib/sqla/tools.py
View file @
4466d365
...
...
@@ -32,6 +32,7 @@ def get_primary_key(model):
pks
.
append
(
get_column_for_current_model
(
p
)
.
key
)
else
:
pks
.
append
(
p
.
key
)
if
len
(
pks
)
==
1
:
return
pks
[
0
]
elif
len
(
pks
)
>
1
:
...
...
flask_admin/helpers.py
View file @
4466d365
from
re
import
sub
from
jinja2
import
contextfunction
from
flask
import
g
,
request
from
wtforms.validators
import
DataRequired
,
InputRequired
...
...
@@ -85,3 +86,13 @@ def get_render_ctx():
Get view template context.
"""
return
getattr
(
g
,
'_admin_render_ctx'
,
None
)
def
prettify_class_name
(
name
):
"""
Split words in PascalCase string into separate words.
:param name:
String to split
"""
return
sub
(
r'(?<=.)([A-Z])'
,
r' \1'
,
name
)
flask_admin/model/base.py
View file @
4466d365
...
...
@@ -483,7 +483,7 @@ class BaseModelView(BaseView, ActionsMixin):
# If name not provided, it is model name
if
name
is
None
:
name
=
'
%
s'
%
self
.
prettify
_name
(
model
.
__name__
)
name
=
'
%
s'
%
self
.
_prettify_class
_name
(
model
.
__name__
)
# If endpoint not provided, it is model name + 'view'
if
endpoint
is
None
:
...
...
@@ -614,7 +614,7 @@ class BaseModelView(BaseView, ActionsMixin):
if
self
.
column_labels
and
field
in
self
.
column_labels
:
return
self
.
column_labels
[
field
]
else
:
return
self
.
prettify_name
(
field
)
return
self
.
_
prettify_name
(
field
)
def
get_list_columns
(
self
):
"""
...
...
@@ -934,7 +934,7 @@ class BaseModelView(BaseView, ActionsMixin):
raise
NotImplemented
()
# Various helpers
def
prettify_name
(
self
,
name
):
def
_
prettify_name
(
self
,
name
):
"""
Prettify pythonic variable name.
...
...
flask_admin/tests/test_base.py
View file @
4466d365
...
...
@@ -354,3 +354,8 @@ def test_menu_links():
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'
)
flask_admin/tests/test_model.py
View file @
4466d365
...
...
@@ -329,3 +329,11 @@ def test_custom_form():
eq_
(
view
.
_edit_form_class
,
TestForm
)
ok_
(
not
hasattr
(
view
.
_create_form_class
,
'col1'
))
def
check_class_name
():
class
DummyView
(
MockModelView
):
pass
view
=
DummyView
(
Model
)
eq_
(
view
.
name
,
'Dummy 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