flask.ext.admin.contrib.fileadmin
¶
-
class
FileAdmin
(base_path, base_url=None, name=None, category=None, endpoint=None, url=None, verify_path=True)[source]¶ Simple file-management interface.
Parameters: - path – Path to the directory which will be managed
- 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.ext.admin import Admin from flask.ext.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¶ Is file upload allowed.
-
can_delete
= True¶ Is file deletion allowed.
-
can_delete_dirs
= True¶ Is recursive directory deletion is allowed.
-
can_mkdir
= True¶ Is directory creation allowed.
-
can_rename
= True¶ Is file and directory renaming allowed.
-
allowed_extensions
= None¶ List of allowed extensions for uploads, in lower case.
Example:
class MyAdmin(FileAdmin): allowed_extensions = ('swf', 'jpg', 'gif', 'png')
-
editable_extensions
= ()¶ List of editable extensions, in lower case.
Example:
class MyAdmin(FileAdmin): editable_extensions = ('md', 'html', 'txt')
-
list_template
= 'admin/file/list.html'¶ File list template
-
upload_template
= 'admin/file/form.html'¶ File upload template
-
mkdir_template
= 'admin/file/form.html'¶ Directory creation (mkdir) template
-
rename_template
= 'admin/file/rename.html'¶ Rename template
-
edit_template
= 'admin/file/edit.html'¶ Edit template
-
can_download
= True¶ Is file download allowed.
-
delete_form
()[source]¶ Instantiate file delete form and return it.
Override to implement custom behavior.
-
edit_form
()[source]¶ Instantiate file editing form and return it.
Override to implement custom behavior.
-
edit_template
= 'admin/file/edit.html' Edit template
-
form_base_class
¶ Base form class. Will be used to create the upload, rename, edit, and delete form.
Allows enabling CSRF validation and useful if you want to have custom contructor or override some fields.
Example:
class MyBaseForm(Form): def do_something(self): pass class MyAdmin(FileAdmin): form_base_class = MyBaseForm
alias of
BaseForm
-
get_base_path
()[source]¶ Return base path. Override to customize behavior (per-user directories, etc)
-
get_delete_form
()[source]¶ Create form class for model delete view.
Override to implement customized behavior.
-
get_edit_form
()[source]¶ Create form class for file editing view.
Override to implement customized behavior.
-
get_name_form
()[source]¶ Create form class for renaming and mkdir views.
Override to implement customized behavior.
-
get_upload_form
()[source]¶ Upload form class for file upload view.
Override to implement customized behavior.
-
index
(*args, **kwargs)[source]¶ Index view method
Parameters: path – Optional directory path. If not provided, will use the base directory
-
is_accessible_path
(path)[source]¶ Verify if the provided path is accessible for the current user.
Override to customize behavior.
Parameters: path – Relative path to the root
-
is_file_allowed
(filename)[source]¶ Verify if file can be uploaded.
Override to customize behavior.
Parameters: filename – Source file name
-
is_file_editable
(filename)[source]¶ Determine if the file can be edited.
Override to customize behavior.
Parameters: filename – Source file name
-
is_in_folder
(base_path, directory)[source]¶ Verify that directory is in base_path folder
Parameters: - base_path – Base directory path
- directory – Directory path to check
-
mkdir
(*args, **kwargs)[source]¶ Directory creation view method
Parameters: path – Optional directory path. If not provided, will use the base directory
-
name_form
()[source]¶ Instantiate form used in rename and mkdir then return it.
Override to implement custom behavior.
-
on_directory_delete
(full_path, dir_name)[source]¶ Perform some actions after a directory has successfully been deleted.
Called from delete method
By default do nothing.
-
on_edit_file
(full_path, path)[source]¶ Perform some actions after a file has been successfully changed.
Called from edit method
By default do nothing.
-
on_file_delete
(full_path, filename)[source]¶ Perform some actions after a file has successfully been deleted.
Called from delete method
By default do nothing.
-
on_file_upload
(directory, path, filename)[source]¶ Perform some actions after a file has been successfully uploaded.
Called from upload method
By default do nothing.
-
on_mkdir
(parent_dir, dir_name)[source]¶ Perform some actions after a directory has successfully been created.
Called from mkdir method
By default do nothing.
-
on_rename
(full_path, dir_base, filename)[source]¶ Perform some actions after a file or directory has been renamed.
Called from rename method
By default do nothing.
-
save_file
(path, file_data)[source]¶ Save uploaded file to the disk
Parameters: - path – Path to save to
- file_data – Werkzeug FileStorage object
-
upload
(*args, **kwargs)[source]¶ Upload view method
Parameters: path – Optional directory path. If not provided, will use the base directory