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
4cc09efa
Commit
4cc09efa
authored
Aug 19, 2012
by
mrjoes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
File admin mass-actions
parent
373448cb
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
91 additions
and
27 deletions
+91
-27
actions.py
flask_admin/actions.py
+1
-1
fileadmin.py
flask_admin/contrib/fileadmin.py
+34
-2
actions.html
flask_admin/templates/admin/actions.html
+13
-17
list.html
flask_admin/templates/admin/file/list.html
+38
-6
list.html
flask_admin/templates/admin/model/list.html
+5
-1
No files found.
flask_admin/actions.py
View file @
4cc09efa
...
...
@@ -43,7 +43,7 @@ class ActionsMixin(object):
self
.
_actions_data
[
name
]
=
(
attr
,
text
,
desc
)
def
is_action_allowed
(
self
,
name
):
return
True
return
name
not
in
self
.
disallowed_actions
def
get_actions_list
(
self
):
actions
=
[]
...
...
flask_admin/contrib/fileadmin.py
View file @
4cc09efa
...
...
@@ -12,6 +12,7 @@ from werkzeug import secure_filename
from
flask
import
flash
,
url_for
,
redirect
,
abort
,
request
from
flask.ext.admin.base
import
BaseView
,
expose
from
flask.ext.admin.actions
import
action
,
ActionsMixin
from
flask.ext.admin.babel
import
gettext
,
lazy_gettext
from
flask.ext.admin
import
form
from
flask.ext
import
wtf
...
...
@@ -54,7 +55,7 @@ class UploadForm(form.BaseForm):
raise
wtf
.
ValidationError
(
gettext
(
'Invalid file type.'
))
class
FileAdmin
(
BaseView
):
class
FileAdmin
(
BaseView
,
ActionsMixin
):
"""
Simple file-management interface.
...
...
@@ -151,6 +152,8 @@ class FileAdmin(BaseView):
self
.
base_path
=
base_path
self
.
base_url
=
base_url
self
.
init_actions
()
self
.
_on_windows
=
platform
.
system
()
==
'Windows'
# Convert allowed_extensions to set for quick validation
...
...
@@ -277,6 +280,12 @@ class FileAdmin(BaseView):
return
base_path
,
directory
,
path
def
is_action_allowed
(
self
,
name
):
if
name
==
'delete'
and
not
self
.
can_delete
:
return
False
return
True
@
expose
(
'/'
)
@
expose
(
'/b/<path:path>'
)
def
index
(
self
,
path
=
None
):
...
...
@@ -315,12 +324,17 @@ class FileAdmin(BaseView):
accumulator
.
append
(
n
)
breadcrumbs
.
append
((
n
,
op
.
join
(
*
accumulator
)))
# Actions
actions
,
actions_confirmation
=
self
.
get_actions_list
()
return
self
.
render
(
self
.
list_template
,
dir_path
=
path
,
breadcrumbs
=
breadcrumbs
,
get_dir_url
=
self
.
_get_dir_url
,
get_file_url
=
self
.
_get_file_url
,
items
=
items
)
items
=
items
,
actions
=
actions
,
actions_confirmation
=
actions_confirmation
)
@
expose
(
'/upload/'
,
methods
=
(
'GET'
,
'POST'
))
@
expose
(
'/upload/<path:path>'
,
methods
=
(
'GET'
,
'POST'
))
...
...
@@ -466,3 +480,21 @@ class FileAdmin(BaseView):
path
=
op
.
dirname
(
path
),
name
=
op
.
basename
(
path
),
dir_url
=
return_url
)
@
expose
(
'/action/'
,
methods
=
(
'POST'
,))
def
action_view
(
self
):
return
self
.
handle_action
()
# Actions
@
action
(
'delete'
,
lazy_gettext
(
'Delete'
),
lazy_gettext
(
'Are you sure you want to delete these files?'
))
def
action_delete
(
self
,
items
):
for
path
in
items
:
base_path
,
full_path
,
path
=
self
.
_normalize_path
(
path
)
try
:
os
.
remove
(
full_path
)
flash
(
gettext
(
'File "
%(name)
s" was successfully deleted.'
,
name
=
path
))
except
Exception
,
ex
:
flash
(
gettext
(
'Failed to delete file:
%(name)
s'
,
name
=
ex
),
'error'
)
flask_admin/templates/admin/actions.html
View file @
4cc09efa
{% macro dropdown(actions) -%}
{% if actions %}
<li
class=
"dropdown"
>
<a
class=
"dropdown-toggle"
data-toggle=
"dropdown"
href=
"#"
>
{{ _gettext('With selected')}}
<b
class=
"caret"
></b>
</a>
<ul
id=
"action_list"
class=
"dropdown-menu"
>
{% for p in actions %}
<li>
<a
href=
"#"
onclick=
"return modelActions.execute('{{ p[0] }}');"
>
{{ _gettext(p[1]) }}
</a>
</li>
{% endfor %}
</ul>
</li>
{% endif %}
{% macro dropdown(btn_class='dropdown-toggle') -%}
<a
class=
"{{ btn_class }}"
data-toggle=
"dropdown"
href=
"#"
>
{{ _gettext('With selected')}}
<b
class=
"caret"
></b>
</a>
<ul
class=
"dropdown-menu"
>
{% for p in actions %}
<li>
<a
href=
"#"
onclick=
"return modelActions.execute('{{ p[0] }}');"
>
{{ _gettext(p[1]) }}
</a>
</li>
{% endfor %}
</ul>
{% endmacro %}
{% macro form(actions,
view
) %}
{% macro form(actions,
url
) %}
{% if actions %}
<form
id=
"action_form"
action=
"{{ url
_for(view)
}}"
method=
"POST"
style=
"display: none"
>
<form
id=
"action_form"
action=
"{{ url }}"
method=
"POST"
style=
"display: none"
>
<input
type=
"hidden"
id=
"action"
name=
"action"
/>
</form>
{% endif %}
...
...
flask_admin/templates/admin/file/list.html
View file @
4cc09efa
{% extends 'admin/master.html' %}
{% import 'admin/lib.html' as lib with context %}
{% import 'admin/actions.html' as actionslib with context %}
{% block body %}
<ul
class=
"breadcrumb"
>
...
...
@@ -21,6 +22,11 @@
<table
class=
"table table-striped table-bordered model-list"
>
<thead>
<tr>
{% if actions %}
<th
class=
"span1"
>
<input
type=
"checkbox"
name=
"rowtoggle"
class=
"action-rowtoggle"
/>
</th>
{% endif %}
<th
class=
"span1"
>
</th>
<th>
Name
</th>
<th>
Size
</th>
...
...
@@ -28,6 +34,13 @@
</thead>
{% for name, path, is_dir, size in items %}
<tr>
{% if actions %}
<td>
{% if not is_dir %}
<input
type=
"checkbox"
name=
"rowid"
class=
"action-checkbox"
value=
"{{ path }}"
/>
{% endif %}
</td>
{% endif %}
<td>
{% if admin_view.can_rename and path and name != '..' %}
<a
class=
"icon"
href=
"{{ url_for('.rename', path=path) }}"
>
...
...
@@ -71,10 +84,29 @@
</tr>
{% endfor %}
</table>
{% if admin_view.can_upload %}
<a
class=
"btn btn-primary btn-large"
href=
"{{ get_dir_url('.upload', path=dir_path) }}"
>
{{ _gettext('Upload File') }}
</a>
{% endif %}
{% if admin_view.can_mkdir %}
<a
class=
"btn btn-primary btn-large"
href=
"{{ get_dir_url('.mkdir', path=dir_path) }}"
>
{{ _gettext('Create Directory') }}
</a>
{% endif %}
<div
class=
"btn-toolbar"
>
{% if admin_view.can_upload %}
<div
class=
"btn-group"
>
<a
class=
"btn btn-primary btn-large"
href=
"{{ get_dir_url('.upload', path=dir_path) }}"
>
{{ _gettext('Upload File') }}
</a>
</div>
{% endif %}
{% if admin_view.can_mkdir %}
<div
class=
"btn-group"
>
<a
class=
"btn btn-primary btn-large"
href=
"{{ get_dir_url('.mkdir', path=dir_path) }}"
>
{{ _gettext('Create Directory') }}
</a>
</div>
{% endif %}
{% if actions %}
<div
class=
"btn-group"
>
{{ actionslib.dropdown('dropdown-toggle btn btn-primary btn-large') }}
</div>
{% endif %}
</div>
{{ actionslib.form(actions, url_for('.action_view')) }}
{% endblock %}
{% block tail %}
{{ actionslib.script(_gettext('Please select at least one file.'),
actions,
actions_confirmation) }}
{% endblock %}
flask_admin/templates/admin/model/list.html
View file @
4cc09efa
...
...
@@ -33,7 +33,11 @@
</li>
{% endif %}
{{ actionlib.dropdown(actions) }}
{% if actions %}
<li
class=
"dropdown"
>
{{ actionlib.dropdown() }}
</li>
{% endif %}
{% if search_supported %}
<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