ox.apps.files
This application provides file management, including: upload, thumbnailing, access rights.
Models
- class ox.apps.files.models.file.File(*args, **kwargs)[source]
Bases:
Described,Timestamped,ChildOwnedThis class represent a file.
Files are looked up for a matching
FileProcessor(reading mime-type). A processors handles different tasks such as creating preview (thumbnails) or getting metadata. In order to do so, it usesregistrythat provides helpers to read mime types and register file processors.A file can be nested under a
parentfolder. IfNoneis provided, then it will be at the root of the filesystem.Each file is also attached to an
ownerthat specifies who has access to the object (usingdjango-capspermission system).At deletion, related files and previews are deleted based on
.conf.ox_files_settings(CLEAR_FILES_ON_DELETE=Trueoption).- Access
alias of
FileAccess
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- delete(*args, clear_files=None, **kwargs)[source]
Ensure file deletion.
- Parameters:
*args –
forward to super’s
delete()clear_files (
bool|None) – if True or False, overrides default settings.**kwargs –
forward to super’s
delete()
- get_processor(save=True, registry=<ox.apps.files.processors.registry.Registry object>)[source]
Return processor to use for this file type.
Read mime-type from file if not already set.
- Parameters:
save – save model if mime type is updated (default is True)
registry – use this processors instead of
processors.processors
- move_or_copy(path, copy=False)[source]
Move file by path.
- Parameters:
path (
str) – path related to upload directory
- parent_attr = 'folder'
Field name used for parenting.
- class ox.apps.files.models.file.FileQuerySet(model=None, query=None, using=None, hints=None)[source]
Bases:
ChildOwnedQuerySet
- ox.apps.files.models.file.file_upload_to(instance, filename)[source]
Return target upload file depending on whether the folder is synchronized or not.
- Return type:
str
- class ox.apps.files.models.folder.Folder(*args, **kwargs)[source]
Bases:
Described,Timestamped,OwnedTreeNodeRepresent a folder in which files are stored.
Important
Updating
parent,nameandpathshould not be done manually. Instead userename()andmove_to()methods to ensure that these values are correctly set.When thoses values raise a ValidationError, user should assume that new values of the model are invalid.
- Access
alias of
FolderAccess
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- move_to(parent=None, name=None, save=True)[source]
Move folder into provided parent folder or root.
- Parameters:
parent (
Folder|None) – parent foldername (
str|None) – if provided rename foldersave (
bool) – save node
- on_save(fields=None)[source]
Ensure tree id, level and path are set.
It also
validate_node()and update children’s values.
- root_grants = {'ox_files.add_file': 1, 'ox_files.add_folder': 1, 'ox_files.change_file': 1, 'ox_files.change_folder': 1, 'ox_files.delete_file': 1, 'ox_files.delete_folder': 1, 'ox_files.view_file': 3, 'ox_files.view_folder': 3}
This class attribute provide the default value for grant object. It should follows the structure of
grantsfield, such as:root_grants = { "auth.view_user": 1, "app.change_mymodel": 2 }
- class ox.apps.files.models.folder.FolderComment(*args, **kwargs)[source]
Bases:
MessageMessage to a file
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- class ox.apps.files.models.folder.FolderQuerySet(model=None, query=None, using=None, hints=None)[source]
Bases:
OwnedTreeNodeQuerySet
File processors
Processors are used to handle file manipulation such as generating thumbnails. They are registered using the ox.apps.files.processors.registry Registry instance.
- class ox.apps.files.processors.Processor[source]
Bases:
objectA Processor handles reading file metadata, providing preview among other things.
- create_preview(path, out, size=(600, 800), force=False, **kwargs)[source]
Create a preview for the file at provided path.
- Parameters:
path (
Path) – path of the file to create a preview ofout (
Path) – output path to save previewsize (thumbnail) – defaults to configured settings.
force (
bool) – create file even if it exists
- Return type:
bool
:return boolean indicating wether file has been created
- class ox.apps.files.processors.Registry(default_processor, processors=[])[source]
Bases:
objectRegistry of all file processor classes.
This is used to determine file type and provide a processor based on it.
- default_processor = None
Default processor to use when file type is not supported by any other processor.
- populate(paths=['ox.apps.files.processors.ImageProcessor', 'ox.apps.files.processors.PDFProcessor', 'ox.apps.files.processors.LibreOfficeProcessor'])[source]
Fullfill registry using provided list of processors class path. :type paths:
list[str] :param paths: class paths (defaults toPROCESSORS)
- ox.apps.files.processors.registry = <ox.apps.files.processors.registry.Registry object>
Default registry of file processors.
ox.apps.files.apps
- class ox.apps.files.apps.AppConfig(*args, **kwargs)[source]
Bases:
AppConfig- icon: str = 'mdi-document-multiple-outline'
Material design icon class.
- npm_package: str | None = '@oxylus/files'
Name of the corresponding NPM package to look up for.
Defaults to app label.
- root_url: str = 'ox/files'
Provide an alternative to app label when we target application in paths.
For example Oxylus will nest template directories as
ox/core/instead ofox_core. The same happens for urls.
ox.apps.files.conf
- class ox.apps.files.conf.Settings(key, source=<LazySettings "instance.settings">)[source]
Bases:
Settings- FILE_SIZE_LIMIT = 15728640
Set maximum file size.
-
MAGIC_BUFFER:
int= 2048 Buffer size used by Python-Magic to read mime types.
- PREVIEW_DIR = 'ox_files/previews'
Directory in protected media which to save previews.
-
PROCESSORS:
list[str] = ['ox.apps.files.processors.ImageProcessor', 'ox.apps.files.processors.PDFProcessor', 'ox.apps.files.processors.LibreOfficeProcessor'] List of file processors.
-
THUMBNAIL_SIZE:
tuple[int,int] = (600, 800) Size for thumbnails
- UPLOAD_DIR = 'ox_files/uploads'
Subdirectory in protected media where to upload files.
-
WEBDAV_HOST:
str= '127.0.0.1' Host for the WebDAV server. Defaults to the first
ALLOWED_HOSTS.
-
WEBDAV_PORT:
int= 8042 Port of the WebDAV server.
- property preview_dir: Path
Return full path to preview dir.
- resolve(path, owner=None, relative=False)[source]
Resolve path under file upload directory.
- Parameters:
path (
str) – path to resolve.owner (
UUID|None) – if provided resolve under this owner’s path.relative (
bool) – if True, return path relative to MEDIA_ROOT.
- property upload_dir: Path
Return full path to upload dir.
- ox.apps.files.conf.ox_files_settings: Settings = <ox.apps.files.conf.Settings object>
Settings used by
ox_filesapplication, using keyOX_FILES.
- ox.apps.files.conf.resolve(path, owner=None, relative=False)
Shortcut to
ox_files_settings‘sSettings.resolve().
ox.apps.files.exceptions
ox.apps.files.filters
ox.apps.files.serializers
- class ox.apps.files.serializers.BaseFileCommentSerializer(*args, **kwargs)[source]
Bases:
MessageSerializer,ModelSerializer
- class ox.apps.files.serializers.BaseFolderCommentSerializer(*args, **kwargs)[source]
Bases:
MessageSerializer,ModelSerializer
- class ox.apps.files.serializers.FileCommentSerializer(*args, **kwargs)[source]
Bases:
BaseFileCommentSerializer
- class ox.apps.files.serializers.FileSerializer(*args, **kwargs)[source]
Bases:
OwnedSerializer- file_data
File data upload
- class ox.apps.files.serializers.FolderCommentSerializer(*args, **kwargs)[source]
Bases:
BaseFolderCommentSerializer
ox.apps.files.tasks
ox.apps.files.views
- class ox.apps.files.views.FileViewSet(**kwargs)[source]
Bases:
OwnedViewSet- serializer_class
alias of
FileSerializer
- class ox.apps.files.views.FolderViewSet(**kwargs)[source]
Bases:
OwnedViewSet- serializer_class
alias of
FolderSerializer