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:

admin = Admin()

path = op.join(op.dirname(__file__), 'static')
admin.add_view(FileAdmin(path, '/static/', name='Static Files'))
admin.setup_app(app)
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(*args, **kwargs)[source]

Delete view method

download(*args, **kwargs)[source]

Download view method.

Parameters:path – File path.
edit(*args, **kwargs)[source]

Edit view method

edit_template = 'admin/file/edit.html'

Edit template

get_base_path()[source]

Return base path. Override to customize behavior (per-user directories, etc)

get_base_url()[source]

Return base URL. Override to customize behavior (per-user directories, etc)

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
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.

rename(*args, **kwargs)[source]

Rename view method

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
upload_form

Upload form class

alias of UploadForm

Related Topics

This Page