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
ccfa163f
Commit
ccfa163f
authored
Dec 18, 2013
by
Serge S. Koval
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #423 from iurisilvio/remove_base_url
Make FileAdmin.base_url optional.
parents
d0ca5f28
a26751d2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
10 deletions
+39
-10
fileadmin.py
flask_admin/contrib/fileadmin.py
+35
-10
list.html
flask_admin/templates/admin/file/list.html
+4
-0
No files found.
flask_admin/contrib/fileadmin.py
View file @
ccfa163f
...
@@ -7,7 +7,7 @@ import shutil
...
@@ -7,7 +7,7 @@ import shutil
from
operator
import
itemgetter
from
operator
import
itemgetter
from
werkzeug
import
secure_filename
from
werkzeug
import
secure_filename
from
flask
import
flash
,
url_for
,
redirect
,
abort
,
request
from
flask
import
flash
,
url_for
,
redirect
,
abort
,
request
,
send_from_directory
from
wtforms
import
fields
,
validators
from
wtforms
import
fields
,
validators
...
@@ -64,13 +64,12 @@ class FileAdmin(BaseView, ActionsMixin):
...
@@ -64,13 +64,12 @@ class FileAdmin(BaseView, ActionsMixin):
"""
"""
Simple file-management interface.
Simple file-management interface.
Requires two parameters:
:param path:
:param path:
Path to the directory which will be managed
Path to the directory which will be managed
:param url:
:param base_url:
Base URL for the directory. Will be used to generate
Optional base URL for the directory. Will be used to generate
static links to the files.
static links to the files. If not defined, a route will be created
to serve uploaded files.
Sample usage::
Sample usage::
...
@@ -86,6 +85,11 @@ class FileAdmin(BaseView, ActionsMixin):
...
@@ -86,6 +85,11 @@ class FileAdmin(BaseView, ActionsMixin):
Is file upload allowed.
Is file upload allowed.
"""
"""
can_download
=
True
"""
Is file download allowed.
"""
can_delete
=
True
can_delete
=
True
"""
"""
Is file deletion allowed.
Is file deletion allowed.
...
@@ -151,7 +155,7 @@ class FileAdmin(BaseView, ActionsMixin):
...
@@ -151,7 +155,7 @@ class FileAdmin(BaseView, ActionsMixin):
Edit template
Edit template
"""
"""
def
__init__
(
self
,
base_path
,
base_url
,
def
__init__
(
self
,
base_path
,
base_url
=
None
,
name
=
None
,
category
=
None
,
endpoint
=
None
,
url
=
None
,
name
=
None
,
category
=
None
,
endpoint
=
None
,
url
=
None
,
verify_path
=
True
):
verify_path
=
True
):
"""
"""
...
@@ -310,10 +314,10 @@ class FileAdmin(BaseView, ActionsMixin):
...
@@ -310,10 +314,10 @@ class FileAdmin(BaseView, ActionsMixin):
Static file path
Static file path
"""
"""
if
self
.
is_file_editable
(
path
):
if
self
.
is_file_editable
(
path
):
r
eturn
url_for
(
".edit"
,
path
=
path
)
r
oute
=
'.edit'
else
:
else
:
base_url
=
self
.
get_base_url
()
route
=
'.download'
return
urljoin
(
base_url
,
path
)
return
url_for
(
route
,
path
=
path
)
def
_normalize_path
(
self
,
path
):
def
_normalize_path
(
self
,
path
):
"""
"""
...
@@ -503,6 +507,27 @@ class FileAdmin(BaseView, ActionsMixin):
...
@@ -503,6 +507,27 @@ class FileAdmin(BaseView, ActionsMixin):
return
self
.
render
(
self
.
upload_template
,
form
=
form
)
return
self
.
render
(
self
.
upload_template
,
form
=
form
)
@
expose
(
'/download/<path:path>'
)
def
download
(
self
,
path
=
None
):
"""
Download view method.
:param path:
File path.
"""
if
not
self
.
can_download
:
abort
(
404
)
base_path
,
directory
,
path
=
self
.
_normalize_path
(
path
)
# backward compatibility with base_url
base_url
=
self
.
get_base_url
()
if
base_url
:
base_url
=
urljoin
(
url_for
(
'.index'
),
base_url
)
return
redirect
(
urljoin
(
base_url
,
path
))
return
send_from_directory
(
base_path
,
path
)
@
expose
(
'/mkdir/'
,
methods
=
(
'GET'
,
'POST'
))
@
expose
(
'/mkdir/'
,
methods
=
(
'GET'
,
'POST'
))
@
expose
(
'/mkdir/<path:path>'
,
methods
=
(
'GET'
,
'POST'
))
@
expose
(
'/mkdir/<path:path>'
,
methods
=
(
'GET'
,
'POST'
))
def
mkdir
(
self
,
path
=
None
):
def
mkdir
(
self
,
path
=
None
):
...
...
flask_admin/templates/admin/file/list.html
View file @
ccfa163f
...
@@ -83,7 +83,11 @@
...
@@ -83,7 +83,11 @@
</td>
</td>
{% else %}
{% else %}
<td>
<td>
{% if admin_view.can_download %}
<a
href=
"{{ get_file_url(path)|safe }}"
>
{{ name }}
</a>
<a
href=
"{{ get_file_url(path)|safe }}"
>
{{ name }}
</a>
{% else %}
{{ name }}
{% endif %}
</td>
</td>
<td>
<td>
{{ size }}
{{ size }}
...
...
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