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
7fb2d6bf
Commit
7fb2d6bf
authored
Dec 16, 2012
by
Serge S. Koval
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #127 from ArtemSerga/#1
Column descriptions support
parents
26b3bf70
5e0ccca8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
20 deletions
+55
-20
form.py
flask_admin/contrib/sqlamodel/form.py
+11
-2
base.py
flask_admin/model/base.py
+16
-0
list.html
flask_admin/templates/admin/model/list.html
+28
-18
No files found.
flask_admin/contrib/sqlamodel/form.py
View file @
7fb2d6bf
...
@@ -44,6 +44,12 @@ class AdminModelConverter(ModelConverterBase):
...
@@ -44,6 +44,12 @@ class AdminModelConverter(ModelConverterBase):
return
self
.
view
.
prettify_name
(
name
)
return
self
.
view
.
prettify_name
(
name
)
def
_get_description
(
self
,
name
,
field_args
):
if
'description'
in
field_args
:
return
field_args
[
'description'
]
if
self
.
view
.
column_descriptions
:
return
self
.
view
.
column_descriptions
.
get
(
name
)
def
_get_field_override
(
self
,
name
):
def
_get_field_override
(
self
,
name
):
form_overrides
=
getattr
(
self
.
view
,
'form_overrides'
,
None
)
form_overrides
=
getattr
(
self
.
view
,
'form_overrides'
,
None
)
...
@@ -67,6 +73,7 @@ class AdminModelConverter(ModelConverterBase):
...
@@ -67,6 +73,7 @@ class AdminModelConverter(ModelConverterBase):
local_column
=
prop
.
local_remote_pairs
[
0
][
0
]
local_column
=
prop
.
local_remote_pairs
[
0
][
0
]
kwargs
[
'label'
]
=
self
.
_get_label
(
prop
.
key
,
kwargs
)
kwargs
[
'label'
]
=
self
.
_get_label
(
prop
.
key
,
kwargs
)
kwargs
[
'description'
]
=
self
.
_get_description
(
prop
.
key
,
kwargs
)
if
local_column
.
nullable
:
if
local_column
.
nullable
:
kwargs
[
'validators'
]
.
append
(
validators
.
Optional
())
kwargs
[
'validators'
]
.
append
(
validators
.
Optional
())
...
@@ -148,8 +155,10 @@ class AdminModelConverter(ModelConverterBase):
...
@@ -148,8 +155,10 @@ class AdminModelConverter(ModelConverterBase):
if
not
column
.
nullable
and
not
isinstance
(
column
.
type
,
Boolean
):
if
not
column
.
nullable
and
not
isinstance
(
column
.
type
,
Boolean
):
kwargs
[
'validators'
]
.
append
(
validators
.
Required
())
kwargs
[
'validators'
]
.
append
(
validators
.
Required
())
# Apply label
# Apply label and description if it isn't inline form field
kwargs
[
'label'
]
=
self
.
_get_label
(
prop
.
key
,
kwargs
)
if
self
.
view
.
model
==
mapper
.
class_
:
kwargs
[
'label'
]
=
self
.
_get_label
(
prop
.
key
,
kwargs
)
kwargs
[
'description'
]
=
self
.
_get_description
(
prop
.
key
,
kwargs
)
# Figure out default value
# Figure out default value
default
=
getattr
(
column
,
'default'
,
None
)
default
=
getattr
(
column
,
'default'
,
None
)
...
...
flask_admin/model/base.py
View file @
7fb2d6bf
...
@@ -129,6 +129,19 @@ class BaseModelView(BaseView, ActionsMixin):
...
@@ -129,6 +129,19 @@ class BaseModelView(BaseView, ActionsMixin):
column_labels = dict(name='Name', last_name='Last Name')
column_labels = dict(name='Name', last_name='Last Name')
"""
"""
column_descriptions
=
None
"""
Dictionary where key is column name and
value is description for `list view` column or add/edit form field.
For example::
class MyModelView(BaseModelView):
column_descriptions = dict(
full_name='First and Last name'
)
"""
column_sortable_list
=
ObsoleteAttr
(
'column_sortable_list'
,
column_sortable_list
=
ObsoleteAttr
(
'column_sortable_list'
,
'sortable_columns'
,
'sortable_columns'
,
None
)
None
)
...
@@ -324,6 +337,9 @@ class BaseModelView(BaseView, ActionsMixin):
...
@@ -324,6 +337,9 @@ class BaseModelView(BaseView, ActionsMixin):
if
self
.
column_type_formatters
is
None
:
if
self
.
column_type_formatters
is
None
:
self
.
column_type_formatters
=
dict
(
typefmt
.
DEFAULT_FORMATTERS
)
self
.
column_type_formatters
=
dict
(
typefmt
.
DEFAULT_FORMATTERS
)
if
self
.
column_descriptions
is
None
:
self
.
column_descriptions
=
dict
()
if
self
.
_filters
:
if
self
.
_filters
:
self
.
_filter_groups
=
[]
self
.
_filter_groups
=
[]
self
.
_filter_dict
=
dict
()
self
.
_filter_dict
=
dict
()
...
...
flask_admin/templates/admin/model/list.html
View file @
7fb2d6bf
...
@@ -108,20 +108,26 @@
...
@@ -108,20 +108,26 @@
{% for c, name in list_columns %}
{% for c, name in list_columns %}
<th>
<th>
{% if admin_view.is_sortable(c) %}
{% if admin_view.is_sortable(c) %}
{% if sort_column == column %}
{% if sort_column == column %}
<a
href=
"{{ sort_url(column, True) }}"
>
<a
href=
"{{ sort_url(column, True) }}"
>
{{ name }}
{{ name }}
{% if sort_desc %}
{% if sort_desc %}
<i
class=
"icon-chevron-up"
></i>
<i
class=
"icon-chevron-up"
></i>
{% else %}
<i
class=
"icon-chevron-down"
></i>
{% endif %}
</a>
{% else %}
{% else %}
<i
class=
"icon-chevron-down"
></i
>
<a
href=
"{{ sort_url(column) }}"
>
{{ name }}
</a
>
{% endif %}
{% endif %}
</a>
{% else %}
{% else %}
<a
href=
"{{ sort_url(column) }}"
>
{{ name }}
</a>
{{ name }}
{% endif %}
{% endif %}
{% else %}
{% if c in admin_view.column_descriptions %}
{{ name }}
<a
class=
"icon-question-sign"
title=
"{{ admin_view.column_descriptions[c] }}"
href=
"#"
data-role=
"tooltip"
></a>
{% endif %}
{% endif %}
</th>
</th>
{% set column = column + 1 %}
{% set column = column + 1 %}
...
@@ -167,6 +173,7 @@
...
@@ -167,6 +173,7 @@
{% block tail %}
{% block tail %}
<script
src=
"{{ url_for('admin.static', filename='js/bootstrap-datepicker.js') }}"
></script>
<script
src=
"{{ url_for('admin.static', filename='js/bootstrap-datepicker.js') }}"
></script>
<script
src=
"{{ url_for('admin.static', filename='js/bootstrap-tooltip.js') }}"
></script>
<script
src=
"{{ url_for('admin.static', filename='js/form.js') }}"
></script>
<script
src=
"{{ url_for('admin.static', filename='js/form.js') }}"
></script>
<script
src=
"{{ url_for('admin.static', filename='js/filters.js') }}"
></script>
<script
src=
"{{ url_for('admin.static', filename='js/filters.js') }}"
></script>
...
@@ -174,14 +181,17 @@
...
@@ -174,14 +181,17 @@
actions,
actions,
actions_confirmation) }}
actions_confirmation) }}
{% if filter_groups is not none and filter_data is not none %}
<script
language=
"javascript"
>
<script
language=
"javascript"
>
(
function
()
{
(
function
(
$
)
{
var
filter
=
new
AdminFilters
(
'#filter_form'
,
'.field-filters'
,
$
(
'[data-role=tooltip]'
).
tooltip
();
{{
admin_view
.
_filter_dict
|
tojson
|
safe
}},
{
%
if
filter_groups
is
not
none
and
filter_data
is
not
none
%
}
{{
filter_data
|
tojson
|
safe
}},
var
filter
=
new
AdminFilters
(
{{
filter_types
|
tojson
|
safe
}});
'#filter_form'
,
'.field-filters'
,
})();
{{
admin_view
.
_filter_dict
|
tojson
|
safe
}},
{{
filter_data
|
tojson
|
safe
}},
{{
filter_types
|
tojson
|
safe
}}
);
{
%
endif
%
}
})(
jQuery
);
</script>
</script>
{% endif %}
{% endblock %}
{% endblock %}
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