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
2e794e94
Commit
2e794e94
authored
Jan 10, 2013
by
Artem Serga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#6 - Make font is bold for required form fields and add template helpers support
parent
68b681cf
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
9 deletions
+21
-9
base.py
flask_admin/base.py
+6
-8
helpers.py
flask_admin/helpers.py
+8
-0
lib.html
flask_admin/templates/admin/lib.html
+7
-1
No files found.
flask_admin/base.py
View file @
2e794e94
...
@@ -2,10 +2,8 @@ from functools import wraps
...
@@ -2,10 +2,8 @@ from functools import wraps
from
re
import
sub
from
re
import
sub
from
flask
import
Blueprint
,
render_template
,
url_for
,
abort
,
g
from
flask
import
Blueprint
,
render_template
,
url_for
,
abort
,
g
from
flask.ext.admin
import
babel
from
flask.ext.admin
import
babel
from
flask.ext.admin
import
helpers
as
h
from
.helpers
import
set_current_view
def
expose
(
url
=
'/'
,
methods
=
(
'GET'
,)):
def
expose
(
url
=
'/'
,
methods
=
(
'GET'
,)):
...
@@ -45,13 +43,12 @@ def _wrap_view(f):
...
@@ -45,13 +43,12 @@ def _wrap_view(f):
@
wraps
(
f
)
@
wraps
(
f
)
def
inner
(
self
,
**
kwargs
):
def
inner
(
self
,
**
kwargs
):
# Store current admin view
# Store current admin view
set_current_view
(
self
)
h
.
set_current_view
(
self
)
# Check if administrative piece is accessible
# Check if administrative piece is accessible
h
=
self
.
_handle_view
(
f
.
__name__
,
**
kwargs
)
abort
=
self
.
_handle_view
(
f
.
__name__
,
**
kwargs
)
if
abort
is
not
None
:
if
h
is
not
None
:
return
abort
return
h
return
f
(
self
,
**
kwargs
)
return
f
(
self
,
**
kwargs
)
...
@@ -224,6 +221,7 @@ class BaseView(object):
...
@@ -224,6 +221,7 @@ class BaseView(object):
# or enabled.
# or enabled.
kwargs
[
'_gettext'
]
=
babel
.
gettext
kwargs
[
'_gettext'
]
=
babel
.
gettext
kwargs
[
'_ngettext'
]
=
babel
.
ngettext
kwargs
[
'_ngettext'
]
=
babel
.
ngettext
kwargs
[
'h'
]
=
h
# Contribute extra arguments
# Contribute extra arguments
kwargs
.
update
(
self
.
_template_args
)
kwargs
.
update
(
self
.
_template_args
)
...
...
flask_admin/helpers.py
View file @
2e794e94
from
flask
import
g
from
flask
import
g
from
wtforms.validators
import
Required
def
set_current_view
(
view
):
def
set_current_view
(
view
):
...
@@ -7,3 +8,10 @@ def set_current_view(view):
...
@@ -7,3 +8,10 @@ def set_current_view(view):
def
get_current_view
():
def
get_current_view
():
return
getattr
(
g
,
'_admin_view'
,
None
)
return
getattr
(
g
,
'_admin_view'
,
None
)
def
is_required_form_field
(
field
):
for
validator
in
field
.
validators
:
if
isinstance
(
validator
,
Required
):
return
True
return
False
flask_admin/templates/admin/lib.html
View file @
2e794e94
...
@@ -78,7 +78,13 @@
...
@@ -78,7 +78,13 @@
{% for f in form if f.type != 'HiddenField' and f.type != 'CSRFTokenField' %}
{% for f in form if f.type != 'HiddenField' and f.type != 'CSRFTokenField' %}
<div
class=
"control-group{% if f.errors %} error{% endif %}"
>
<div
class=
"control-group{% if f.errors %} error{% endif %}"
>
{{ f.label(class='control-label') }}
<div
class=
"control-label"
>
{% if h.is_required_form_field(f) %}
<strong>
{{ f.label.text }}
</strong>
{% else %}
{{ f.label.text }}
{% endif %}
</div>
<div
class=
"controls"
>
<div
class=
"controls"
>
<div>
<div>
{% if not focus_set %}
{% if not focus_set %}
...
...
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