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
e146f3ff
Commit
e146f3ff
authored
Dec 22, 2015
by
Arthur Bressan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renames FileAdmin to BaseFileAdmin and creates a FileAdmin with a default local storage
parent
565f9e43
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
37 deletions
+46
-37
fileadmin.py
flask_admin/contrib/fileadmin.py
+46
-37
No files found.
flask_admin/contrib/fileadmin.py
View file @
e146f3ff
...
@@ -21,6 +21,12 @@ from flask_admin.babel import gettext, lazy_gettext
...
@@ -21,6 +21,12 @@ from flask_admin.babel import gettext, lazy_gettext
class
LocalFileStorage
(
object
):
class
LocalFileStorage
(
object
):
def
__init__
(
self
,
base_path
):
def
__init__
(
self
,
base_path
):
"""
Constructor.
:param base_path:
Base file storage location
"""
self
.
base_path
=
as_unicode
(
base_path
)
self
.
base_path
=
as_unicode
(
base_path
)
self
.
separator
=
os
.
sep
self
.
separator
=
os
.
sep
...
@@ -114,29 +120,7 @@ class LocalFileStorage(object):
...
@@ -114,29 +120,7 @@ class LocalFileStorage(object):
file_data
.
save
(
path
)
file_data
.
save
(
path
)
class
FileAdmin
(
BaseView
,
ActionsMixin
):
class
BaseFileAdmin
(
BaseView
,
ActionsMixin
):
"""
Simple file-management interface.
:param path:
Path to the directory which will be managed
:param base_url:
Optional base URL for the directory. Will be used to generate
static links to the files. If not defined, a route will be created
to serve uploaded files.
Sample usage::
import os.path as op
from flask_admin import Admin
from flask_admin.contrib.fileadmin import FileAdmin
admin = Admin()
path = op.join(op.dirname(__file__), 'static')
admin.add_view(FileAdmin(path, '/static/', name='Static Files'))
"""
can_upload
=
True
can_upload
=
True
"""
"""
...
@@ -264,15 +248,12 @@ class FileAdmin(BaseView, ActionsMixin):
...
@@ -264,15 +248,12 @@ class FileAdmin(BaseView, ActionsMixin):
edit_modal
=
False
edit_modal
=
False
"""Setting this to true will display the edit view as a modal dialog."""
"""Setting this to true will display the edit view as a modal dialog."""
def
__init__
(
self
,
base_path
,
base_url
=
None
,
def
__init__
(
self
,
base_url
=
None
,
name
=
None
,
category
=
None
,
endpoint
=
None
,
name
=
None
,
category
=
None
,
endpoint
=
None
,
url
=
None
,
url
=
None
,
verify_path
=
True
,
menu_class_name
=
None
,
verify_path
=
True
,
menu_class_name
=
None
,
menu_icon_type
=
None
,
menu_icon_value
=
None
,
menu_icon_type
=
None
,
menu_icon_value
=
None
,
storage
=
None
):
storage
=
LocalFileStorage
,
storage_args
=
None
):
"""
"""
Constructor.
Constructor.
:param base_path:
Base file storage location
:param base_url:
:param base_url:
Base URL for the files
Base URL for the files
:param name:
:param name:
...
@@ -286,13 +267,11 @@ class FileAdmin(BaseView, ActionsMixin):
...
@@ -286,13 +267,11 @@ class FileAdmin(BaseView, ActionsMixin):
:param verify_path:
:param verify_path:
Verify if path exists. If set to `True` and path does not exist
Verify if path exists. If set to `True` and path does not exist
will raise an exception.
will raise an exception.
:param storage:
The storage backend that the `BaseFileAdmin` will use to operate on the files.
"""
"""
if
storage_args
is
None
:
storage_args
=
{}
storage_args
.
setdefault
(
'base_path'
,
base_path
)
self
.
base_url
=
base_url
self
.
base_url
=
base_url
self
.
storage
=
storage
(
**
storage_args
)
self
.
storage
=
storage
self
.
init_actions
()
self
.
init_actions
()
...
@@ -308,8 +287,9 @@ class FileAdmin(BaseView, ActionsMixin):
...
@@ -308,8 +287,9 @@ class FileAdmin(BaseView, ActionsMixin):
not
isinstance
(
self
.
editable_extensions
,
set
)):
not
isinstance
(
self
.
editable_extensions
,
set
)):
self
.
editable_extensions
=
set
(
self
.
editable_extensions
)
self
.
editable_extensions
=
set
(
self
.
editable_extensions
)
super
(
FileAdmin
,
self
)
.
__init__
(
name
,
category
,
endpoint
,
url
,
super
(
BaseFileAdmin
,
self
)
.
__init__
(
name
,
category
,
endpoint
,
url
,
menu_class_name
=
menu_class_name
,
menu_icon_type
=
menu_icon_type
,
menu_class_name
=
menu_class_name
,
menu_icon_type
=
menu_icon_type
,
menu_icon_value
=
menu_icon_value
)
menu_icon_value
=
menu_icon_value
)
def
is_accessible_path
(
self
,
path
):
def
is_accessible_path
(
self
,
path
):
...
@@ -1090,3 +1070,32 @@ class FileAdmin(BaseView, ActionsMixin):
...
@@ -1090,3 +1070,32 @@ class FileAdmin(BaseView, ActionsMixin):
@
action
(
'edit'
,
lazy_gettext
(
'Edit'
))
@
action
(
'edit'
,
lazy_gettext
(
'Edit'
))
def
action_edit
(
self
,
items
):
def
action_edit
(
self
,
items
):
return
redirect
(
self
.
get_url
(
'.edit'
,
path
=
items
))
return
redirect
(
self
.
get_url
(
'.edit'
,
path
=
items
))
class
FileAdmin
(
BaseFileAdmin
):
"""
Simple file-management interface.
:param base_path:
Path to the directory which will be managed
:param base_url:
Optional base URL for the directory. Will be used to generate
static links to the files. If not defined, a route will be created
to serve uploaded files.
Sample usage::
import os.path as op
from flask_admin import Admin
from flask_admin.contrib.fileadmin import FileAdmin
admin = Admin()
path = op.join(op.dirname(__file__), 'static')
admin.add_view(FileAdmin(path, '/static/', name='Static Files'))
"""
def
__init__
(
self
,
base_path
,
*
args
,
**
kwargs
):
storage
=
LocalFileStorage
(
base_path
)
super
(
FileAdmin
,
self
)
.
__init__
(
*
args
,
storage
=
storage
,
**
kwargs
)
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