flask.ext.superadmin.contrib.fileadmin

class flask.ext.superadmin.contrib.fileadmin.FileAdmin(base_path, base_url, name=None, category=None, endpoint=None, url=None)[source]

Simple file-management interface.

Requires two parameters:

path
Path to the directory which will be managed
url
Base URL for the directory. Will be used to generate static links to the 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')
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

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

Delete view method

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

path
Optional directory path. If not provided, will use base directory
is_accessible_path(path)[source]

Verify if path is accessible for current user.

Override to customize behavior.

path
Relative path to the root
is_file_allowed(filename)[source]

Verify if file can be uploaded.

Override to customize behavior.

filename
Source file name
is_in_folder(base_path, directory)[source]

Verify if directory is in base_path folder

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

Directory creation view method

path
Optional directory path. If not provided, will use base directory
rename(*args, **kwargs)[source]

Rename view method

save_file(path, file_data)[source]

Save uploaded file to the disk

path
Path to save to
file_data
Werkzeug FileStorage object
upload(*args, **kwargs)[source]

Upload view method

path
Optional directory path. If not provided, will use base directory