file.models.file
Classes
A customized version of Depot's uploaded file field. This version |
|
Files are not made available for elasticsearch by default. This is |
|
A general file (image, document, pdf, etc), referenced in the database. |
Functions
|
Locks the metadata from a |
|
|
|
Module Contents
- class file.models.file._UploadedFileColumn[source]
Bases:
sqlalchemy.Column[depot.fields.upload.UploadedFile]
- class file.models.file.UploadedFileField(filters=tuple(), upload_type=UploadedFile, upload_storage=None, *args, **kw)[source]
Bases:
depot.fields.sqlalchemy.UploadedFileFieldA customized version of Depot’s uploaded file field. This version stores its data in a JSONB field, instead of using text.
- load_dialect_impl(dialect: sqlalchemy.engine.Dialect) sqlalchemy.sql.type_api.TypeEngine[depot.fields.upload.UploadedFile][source]
Return a
TypeEngineobject corresponding to a dialect.This is an end-user override hook that can be used to provide differing types depending on the given dialect. It is used by the
TypeDecoratorimplementation oftype_engine()to help determine what type should ultimately be returned for a givenTypeDecorator.By default returns
self.impl.
- process_bind_param(value: depot.fields.upload.UploadedFile | None, dialect: sqlalchemy.engine.Dialect) depot.fields.upload.UploadedFile | None[source]
Receive a bound parameter value to be converted.
Subclasses override this method to return the value that should be passed along to the underlying
TypeEngineobject, and from there to the DBAPIexecute()method.The operation could be anything desired to perform custom behavior, such as transforming or serializing data. This could also be used as a hook for validating logic.
This operation should be designed with the reverse operation in mind, which would be the process_result_value method of this class.
- Parameters:
value – Data to operate upon, of any type expected by this method in the subclass. Can be
None.dialect – the
Dialectin use.
- process_result_value(value: dict[str, Any] | None, dialect: sqlalchemy.engine.Dialect) depot.fields.upload.UploadedFile | None[source]
Receive a result-row column value to be converted.
Subclasses should implement this method to operate on data fetched from the database.
Subclasses override this method to return the value that should be passed back to the application, given a value that is already processed by the underlying
TypeEngineobject, originally from the DBAPI cursor methodfetchone()or similar.The operation could be anything desired to perform custom behavior, such as transforming or serializing data. This could also be used as a hook for validating logic.
- Parameters:
value – Data to operate upon, of any type expected by this method in the subclass. Can be
None.dialect – the
Dialectin use.
This operation should be designed to be reversible by the “process_bind_param” method of this class.
- class file.models.file.SearchableFile[source]
Bases:
onegov.search.ORMSearchableFiles are not made available for elasticsearch by default. This is for security reasons - files are public by default but one has to know the url (a very long id).
Search might lead to a disclosure of all files, which is why files can only be searched if they are of a different polymorphic subclass and use this mixin.
- fts_public = True[source]
Returns True if the model is available to be found by the public. If false, only editors/admins will see this object in the search results.
- fts_properties[source]
Returns the type mapping of this model. Each property in the mapping will be read from the model instance.
- property fts_suggestion: str[source]
Returns suggest-as-you-type value of the document. The field used for this property should also be indexed, or the suggestion will lead to nowhere.
If a single string is returned, the completion input equals the completion output. (My Title -> My Title)
If an array of strings is returned, all values are possible inputs and the first value is the output. (My Title/Title My -> My Title)
- class file.models.file.File[source]
Bases:
onegov.core.orm.Base,onegov.core.orm.abstract.Associable,onegov.core.orm.mixins.TimestampMixinA general file (image, document, pdf, etc), referenced in the database.
Thanks to the use of Depot files can be seemingly stored in the database (with transaction guarantees), without actually storing it in the database.
- reference: _UploadedFileColumn[source]
- property file_id: str[source]
The file_id of the contained reference.
If
virtual_file_idis not None, it is returned instead.
- property claimed_extension: str[source]
Returns the extension as defined by the file name or by the content type (whatever is found first in this order).
Note that this extension could therefore not be correct. It is mainly meant for display purposes.
If you need to know the type of a file you should use the content type stored on the reference.
- file.models.file.metadata_lock(metadata_path: _typeshed.StrPath, timeout: float = 0.0) collections.abc.Iterator[bool][source]
Locks the metadata from a
filedepot.io.local.LocalStoredFile. Tries to acquire the lock repeatedly in a spin lock until timeout expires, it will return whether or not it managed to acquire the lock