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
8f259de4
Commit
8f259de4
authored
May 08, 2013
by
Serge S. Koval
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed #221. is_visible method.
parent
0513e9d1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
4 deletions
+27
-4
simple.py
examples/sqla/simple.py
+3
-0
base.py
flask_admin/base.py
+22
-2
layout.html
flask_admin/templates/admin/layout.html
+2
-2
No files found.
examples/sqla/simple.py
View file @
8f259de4
...
...
@@ -117,6 +117,9 @@ class PostAdmin(sqlamodel.ModelView):
text
=
dict
(
label
=
'Big Text'
,
validators
=
[
wtf
.
required
()])
)
def
is_visible
(
self
):
return
False
def
__init__
(
self
,
session
):
# Just call parent class with predefined model.
super
(
PostAdmin
,
self
)
.
__init__
(
Post
,
session
)
...
...
flask_admin/base.py
View file @
8f259de4
...
...
@@ -255,6 +255,17 @@ class BaseView(object):
"""
return
sub
(
r'(?<=.)([A-Z])'
,
r' \1'
,
name
)
def
is_visible
(
self
):
"""
Override this method if you want dynamically hide or show administrative views
from Flask-Admin menu structure
By default, item is visible in menu.
Please note that item should be both visible and accessible to be displayed in menu.
"""
return
True
def
is_accessible
(
self
):
"""
Override this method to add permission checks.
...
...
@@ -354,6 +365,12 @@ class MenuItem(object):
return
view
.
url
in
self
.
_children_urls
def
is_visible
(
self
):
if
self
.
_view
is
None
:
return
False
return
self
.
_view
.
is_visible
()
def
is_accessible
(
self
):
if
self
.
_view
is
None
:
return
False
...
...
@@ -364,12 +381,12 @@ class MenuItem(object):
return
self
.
_view
is
None
def
get_children
(
self
):
return
[
c
for
c
in
self
.
_children
if
c
.
is_accessible
()]
return
[
c
for
c
in
self
.
_children
if
c
.
is_accessible
()
and
c
.
is_visible
()
]
class
MenuLink
(
object
):
"""
Menu additional links hierarchy
.
Additional menu links
.
"""
def
__init__
(
self
,
name
,
url
=
None
,
endpoint
=
None
):
self
.
name
=
name
...
...
@@ -379,6 +396,9 @@ class MenuLink(object):
def
get_url
(
self
):
return
self
.
url
or
url_for
(
self
.
endpoint
)
def
is_visible
(
self
):
return
True
def
is_accessible
(
self
):
return
True
...
...
flask_admin/templates/admin/layout.html
View file @
8f259de4
...
...
@@ -15,7 +15,7 @@
</li>
{% endif %}
{% else %}
{% if item.is_accessible() %}
{% if item.is_accessible()
and item.is_visible()
%}
{% if item.is_active(admin_view) %}
<li
class=
"active"
>
{% else %}
<li>
{% endif %}
<a
href=
"{{ item.get_url() }}"
>
{{ item.name }}
</a>
</li>
...
...
@@ -26,7 +26,7 @@
{% macro menu_links() %}
{% for item in admin_view.admin.menu_links() %}
{% if item.is_accessible() %}
{% if item.is_accessible()
and item.is_visible()
%}
<li>
<a
href=
"{{ item.get_url() }}"
>
{{ item.name }}
</a>
</li>
...
...
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