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
adf7a6c8
Commit
adf7a6c8
authored
Mar 22, 2012
by
Serge S. Koval
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sanity checks, updated quickstart.
parent
f89f33fd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
2 deletions
+41
-2
quickstart.rst
doc/quickstart.rst
+24
-1
fileadmin.py
flask_adminex/ext/fileadmin.py
+16
-0
list.html
flask_adminex/templates/admin/file/list.html
+1
-1
No files found.
doc/quickstart.rst
View file @
adf7a6c8
...
@@ -194,11 +194,34 @@ class and implementing database-related methods.
...
@@ -194,11 +194,34 @@ class and implementing database-related methods.
Please refer to :mod:`flask.ext.adminex.ext.sqlamodel` documentation on how to customize behavior of model-based administrative views.
Please refer to :mod:`flask.ext.adminex.ext.sqlamodel` documentation on how to customize behavior of model-based administrative views.
File Admin
----------
Flask-AdminEx comes with another handy battery - file admin. It gives you ability to manage files on your server (upload, delete, rename, etc).
Here is simple example::
from flask.ext.adminex.ext.fileadmin import FileAdmin
import os.path as op
# Flask setup here
admin = Admin()
path = op.join(op.dirname(__file__), 'static')
admin.add_view(path, '/static/', name='Static Files')
admin.setup_app(app)
You can disable uploads, disable file or directory deletion, restrict file uploads to certain types and so on.
Check :mod:`flask.ext.adminex.ext.fileadmin` documentation on how to do it.
Examples
Examples
--------
--------
Flask-AdminEx comes with
three
samples:
Flask-AdminEx comes with
four
samples:
- `Simple administrative interface <https://github.com/MrJoes/Flask-AdminEx/tree/master/examples/simple>`_ with custom administrative views
- `Simple administrative interface <https://github.com/MrJoes/Flask-AdminEx/tree/master/examples/simple>`_ with custom administrative views
- `SQLAlchemy model example <https://github.com/MrJoes/Flask-AdminEx/tree/master/examples/sqla>`_
- `SQLAlchemy model example <https://github.com/MrJoes/Flask-AdminEx/tree/master/examples/sqla>`_
- `Flask-Login integration example <https://github.com/MrJoes/Flask-AdminEx/tree/master/examples/auth>`_
- `Flask-Login integration example <https://github.com/MrJoes/Flask-AdminEx/tree/master/examples/auth>`_
- `File management interface <https://github.com/MrJoes/Flask-AdminEx/tree/master/examples/file>`_
flask_adminex/ext/fileadmin.py
View file @
adf7a6c8
...
@@ -297,6 +297,10 @@ class FileAdmin(BaseView):
...
@@ -297,6 +297,10 @@ class FileAdmin(BaseView):
# Get path and verify if it is valid
# Get path and verify if it is valid
base_path
,
directory
,
path
=
self
.
_normalize_path
(
path
)
base_path
,
directory
,
path
=
self
.
_normalize_path
(
path
)
if
not
self
.
can_upload
:
flash
(
'File uploading is disabled.'
,
'error'
)
return
redirect
(
self
.
_get_dir_url
(
'.index'
,
path
))
form
=
UploadForm
(
request
.
form
,
self
)
form
=
UploadForm
(
request
.
form
,
self
)
if
form
.
validate_on_submit
():
if
form
.
validate_on_submit
():
filename
=
op
.
join
(
directory
,
filename
=
op
.
join
(
directory
,
...
@@ -326,6 +330,10 @@ class FileAdmin(BaseView):
...
@@ -326,6 +330,10 @@ class FileAdmin(BaseView):
dir_url
=
self
.
_get_dir_url
(
'.index'
,
path
)
dir_url
=
self
.
_get_dir_url
(
'.index'
,
path
)
if
not
self
.
can_mkdir
:
flash
(
'Directory creation is disabled.'
,
'error'
)
return
redirect
(
dir_url
)
form
=
NameForm
(
request
.
form
)
form
=
NameForm
(
request
.
form
)
if
form
.
validate_on_submit
():
if
form
.
validate_on_submit
():
...
@@ -354,6 +362,10 @@ class FileAdmin(BaseView):
...
@@ -354,6 +362,10 @@ class FileAdmin(BaseView):
return_url
=
self
.
_get_dir_url
(
'.index'
,
op
.
dirname
(
path
))
return_url
=
self
.
_get_dir_url
(
'.index'
,
op
.
dirname
(
path
))
if
not
self
.
can_delete
:
flash
(
'Deletion is disabled.'
)
return
redirect
(
return_url
)
if
op
.
isdir
(
full_path
):
if
op
.
isdir
(
full_path
):
if
not
self
.
can_delete_dirs
:
if
not
self
.
can_delete_dirs
:
return
redirect
(
return_url
)
return
redirect
(
return_url
)
...
@@ -386,6 +398,10 @@ class FileAdmin(BaseView):
...
@@ -386,6 +398,10 @@ class FileAdmin(BaseView):
return_url
=
self
.
_get_dir_url
(
'.index'
,
op
.
dirname
(
path
))
return_url
=
self
.
_get_dir_url
(
'.index'
,
op
.
dirname
(
path
))
if
not
self
.
can_rename
:
flash
(
'Renaming is disabled.'
)
return
redirect
(
return_url
)
if
not
op
.
exists
(
full_path
):
if
not
op
.
exists
(
full_path
):
flash
(
'Path does not exist.'
)
flash
(
'Path does not exist.'
)
return
redirect
(
return_url
)
return
redirect
(
return_url
)
...
...
flask_adminex/templates/admin/file/list.html
View file @
adf7a6c8
...
@@ -35,7 +35,7 @@
...
@@ -35,7 +35,7 @@
</a>
</a>
{% endif %}
{% endif %}
{%- if admin_view.can_delete and path -%}
{%- if admin_view.can_delete and path -%}
{% if is_dir %}
{% if is_dir
and admin_view.can_delete_dirs
%}
{% if name != '..' %}
{% if name != '..' %}
<form
class=
"icon"
method=
"POST"
action=
"{{ url_for('.delete') }}"
>
<form
class=
"icon"
method=
"POST"
action=
"{{ url_for('.delete') }}"
>
<input
type=
"hidden"
name=
"path"
value=
"{{ path }}"
></input>
<input
type=
"hidden"
name=
"path"
value=
"{{ path }}"
></input>
...
...
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