org.models.file

Contains the models describing files and images.

Module Contents

Classes

DateInterval

GroupFilesByDateMixin

Abstract base class for generic types.

GeneralFile

A general file (image, document, pdf, etc), referenced in the database.

ImageFile

A general file (image, document, pdf, etc), referenced in the database.

ImageSet

A set of files that belong together. Each file may be part of

ImageSetCollection

Manages filesets.

GeneralFileCollection

Manages files.

BaseImageFileCollection

Manages files.

ImageFileCollection

Manages files.

Attributes

_T

FileT

org.models.file._T[source]
org.models.file.FileT[source]
class org.models.file.DateInterval[source]

Bases: NamedTuple

name: str[source]
start: datetime.datetime[source]
end: datetime.datetime[source]
class org.models.file.GroupFilesByDateMixin[source]

Bases: Generic[FileT]

Abstract base class for generic types.

A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as:

class Mapping(Generic[KT, VT]):
    def __getitem__(self, key: KT) -> VT:
        ...
    # Etc.

This class can then be used as follows:

def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT:
    try:
        return mapping[key]
    except KeyError:
        return default
get_date_intervals(today: datetime.datetime) Iterator[DateInterval][source]
query_intervals(intervals: Iterable[DateInterval], before_filter: Callable[[Query[FileT]], Query[_RowT]], process: Callable[[_RowT], _T]) Iterator[tuple[str, _T]][source]
query_intervals(intervals: Iterable[DateInterval], before_filter: None, process: Callable[[FileT], _T]) Iterator[tuple[str, _T]]
query_intervals(intervals: Iterable[DateInterval], before_filter: None = None, *, process: Callable[[FileT], _T]) Iterator[tuple[str, _T]]
query_intervals(intervals: Iterable[DateInterval], before_filter: Callable[[Query[FileT]], Query[Any]] | None = None, process: None = None) Iterator[tuple[str, Any]]
grouped_by_date(today: datetime.datetime | None = None, id_only: Literal[True] = True) groupby[str, tuple[str, str]][source]
grouped_by_date(today: datetime.datetime | None, id_only: Literal[False]) groupby[str, tuple[str, FileT]]
grouped_by_date(today: datetime.datetime | None = None, *, id_only: Literal[False]) groupby[str, tuple[str, FileT]]

Returns all files grouped by natural language dates.

By default, only ids are returned, as this is enough to build the necessary links, which is what you usually want from a file.

The given date is expected to be in UTC.

class org.models.file.GeneralFile[source]

Bases: onegov.file.File, onegov.file.SearchableFile

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

property access: str[source]
property es_public: bool[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.

__mapper_args__[source]
linked_accesses: onegov.core.orm.mixins.dict_property[dict[str, str]][source]
linked_accesses[source]
class org.models.file.ImageFile[source]

Bases: onegov.file.File

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

__mapper_args__[source]
class org.models.file.ImageSet[source]

Bases: onegov.file.FileSet, onegov.org.models.extensions.AccessExtension, onegov.search.ORMSearchable

A set of files that belong together. Each file may be part of none, one or many sets. Each set may containe none, one or many files.

The fileset uses uuids for public urls instead of a readable url-safe name, because files are meant to be always public with an unguessable url, and so the filesets containing files must also have the same property.

Otherwise we might not be able to guess the name the of the file, but we will be able to guess the name of a fileset containing files.

property es_public: bool[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.

property es_suggestions: dict[str, list[str]][source]
__mapper_args__[source]
es_properties[source]
lead: onegov.core.orm.mixins.dict_property[str | None][source]
view: onegov.core.orm.mixins.dict_property[str | None][source]
show_images_on_homepage: onegov.core.orm.mixins.dict_property[bool | None][source]
class org.models.file.ImageSetCollection(session: sqlalchemy.orm.Session)[source]

Bases: onegov.file.FileSetCollection[ImageSet]

Manages filesets.

class org.models.file.GeneralFileCollection(session: sqlalchemy.orm.Session, order_by: str = 'name')[source]

Bases: onegov.file.FileCollection[GeneralFile], GroupFilesByDateMixin[GeneralFile]

Manages files.

Parameters:
  • session – The SQLAlchemy db session to use.

  • type – The polymorphic type to use and to filter for, or ‘*’ for all.

  • allow_duplicates

    Prevents duplicates if set to false. Duplicates are detected before pre-processing, so already stored files may be downloaded and added again, as they might have changed during the upload.

    Note that this does not change existing files. It only prevents new duplicates from being added.

property statement: sqlalchemy.sql.Select[source]
property files: Query[FileRow][source]
supported_content_types = 'all'[source]
file_list[source]
for_order(order: str) typing_extensions.Self[source]
intervals() tuple[DateInterval, Ellipsis][source]
group(record: FileRow) str[source]
class org.models.file.BaseImageFileCollection(session: sqlalchemy.orm.Session, type: Literal[*, generic] = '*', allow_duplicates: bool = True)[source]
class org.models.file.BaseImageFileCollection(session: sqlalchemy.orm.Session, type: str, allow_duplicates: bool = True)

Bases: onegov.file.FileCollection[FileT], GroupFilesByDateMixin[FileT]

Manages files.

Parameters:
  • session – The SQLAlchemy db session to use.

  • type – The polymorphic type to use and to filter for, or ‘*’ for all.

  • allow_duplicates

    Prevents duplicates if set to false. Duplicates are detected before pre-processing, so already stored files may be downloaded and added again, as they might have changed during the upload.

    Note that this does not change existing files. It only prevents new duplicates from being added.

supported_content_types[source]
class org.models.file.ImageFileCollection(session: sqlalchemy.orm.Session)[source]

Bases: BaseImageFileCollection[ImageFile]

Manages files.

Parameters:
  • session – The SQLAlchemy db session to use.

  • type – The polymorphic type to use and to filter for, or ‘*’ for all.

  • allow_duplicates

    Prevents duplicates if set to false. Duplicates are detected before pre-processing, so already stored files may be downloaded and added again, as they might have changed during the upload.

    Note that this does not change existing files. It only prevents new duplicates from being added.