core.mixins package

core.mixins for the core of Eonvelope project.

class core.mixins.DownloadMixin[source]

Bases: object

Mixin providing a property to check whether a model instance provides a download.

Designed for use in combination with core.mixins.FilePathModelMixin.

property has_download: bool

Checks whether a download is possible for the instance.

get_absolute_download_url()[source]

Returns the url of the download api endpoint.

Return type:

str

class core.mixins.FavoriteModelMixin(*args, **kwargs)[source]

Bases: Model

Mixin adding a favorite functionality to a model class.

is_favorite

Flags favorite accounts. False by default.

class Meta[source]

Bases: object

Metadata class for the mixin, abstract to avoid makemigrations picking it up.

abstract = False
toggle_favorite()[source]

Toggles the is_favorite flag on the model instance.

Return type:

None

_meta = <Options for FavoriteModelMixin>
get_absolute_toggle_favorite_url()[source]

Gets the upload webview url for the model instance.

Return type:

str

Returns:

The upload webview url for the model instance.

class core.mixins.FilePathModelMixin(*args, **kwargs)[source]

Bases: Model

Mixin adding functionality for managing a single storage file for a model class.

file_path

The relative path in the storage where the file is stored. Can be null if no file has been saved (null does not collide with the unique constraint.).

class Meta[source]

Bases: object

Metadata class for the mixin, abstract to avoid makemigrations picking it up.

abstract = False
save(*args, **kwargs)[source]

Extended :django:django.models.Model.save() method.

Saves the data to storage if configured.

Return type:

None

Parameters:
_get_storage_file_name()[source]

Create the filename for the stored file.

Return type:

str

open_file(mode='rb')[source]

Opens and returns the stored file as a filestream.

Note

Use inside a with block.

Parameters:

mode (str) – The mode the file is opened in.

Return type:

File

Returns:

The filestream of the file.

Raises:

FileNotFoundError – If the file_path is not set or the file is not found in the storage.

delete_file()[source]

Deletes the file and sets file_path to None.

Intended for use in a signal.

Return type:

None

_meta = <Options for FilePathModelMixin>
property absolute_filepath: str | None

The absolute filepath in the server fs for use with open.

Returns:

The absolute path in the stored file. If no file_path is set, returns None.

class core.mixins.HealthModelMixin(*args, **kwargs)[source]

Bases: Model

Mixin adding a health functionality to a model class.

is_healthy

Flags whether the model instance is subject to errors. None by default.

last_error

The latest error in connection with the model instance.

last_error_occurred_at

The time of occurrence of the latest error.

class Meta[source]

Bases: object

Metadata class for the mixin, abstract to avoid makemigrations picking it up.

abstract = False
_meta = <Options for HealthModelMixin>
set_unhealthy(errormessage)[source]

Sets the is_healthy flag to False and adds the last_error and its time.

Only saves if the model is already in the database.

Parameters:

errormessage (str | Exception) – The error causing the health change or its message.

Return type:

None

set_healthy()[source]

Sets the is_healthy flag to True.

Runs only if the model is not already healthy. Only saves if the model is already in the database.

Return type:

None

class core.mixins.ThumbnailMixin[source]

Bases: object

Mixin providing a property to check whether a model instance provides a thumbail image.

Designed for use in combination with core.mixins.FilePathModelMixin.

property has_thumbnail: bool

Checks whether a thumbnail download is possible for the instance.

get_absolute_thumbnail_url()[source]

Returns the url of the thumbail download api endpoint.

Return type:

str

class core.mixins.TimestampModelMixin(*args, **kwargs)[source]

Bases: Model

Mixin adding creation and update timestamps to a model class.

created

The datetime the model instance was created. Is set automatically.

updated

The datetime the model instance entry was last updated. Is set automatically.

class Meta[source]

Bases: object

Metadata class for the mixin, abstract to avoid makemigrations picking it up.

abstract = False
get_latest_by = 'created'
_meta = <Options for TimestampModelMixin>
get_next_by_created(*, field=<django.db.models.fields.DateTimeField: created>, is_next=True, **kwargs)
get_next_by_updated(*, field=<django.db.models.fields.DateTimeField: updated>, is_next=True, **kwargs)
get_previous_by_created(*, field=<django.db.models.fields.DateTimeField: created>, is_next=False, **kwargs)
get_previous_by_updated(*, field=<django.db.models.fields.DateTimeField: updated>, is_next=False, **kwargs)
class core.mixins.URLMixin[source]

Bases: object

Mixin to add url features to a django.db.models.Model.

BASENAME = ''
get_absolute_url()[source]

Gets the detail webview url for the model instance.

Note

Used by django.views.generics.ModelFormMixin for redirection.

Return type:

str

Returns:

The detail webview url for the model instance.

get_absolute_edit_url()[source]

Gets the edit webview url for the model instance.

Return type:

str

Returns:

The edit webview url for the model instance.

get_absolute_list_url()[source]

Gets the list webview url for the model instance.

Return type:

str

Returns:

The list webview url for the model instance.

get_absolute_table_url()[source]

Gets the table webview url for the model instance.

Return type:

str

Returns:

The table webview url for the model instance.

get_absolute_api_list_url()[source]

Gets the list api url for the model instance.

Return type:

str

Returns:

The list api url for the model instance.

classmethod get_list_web_url_name()[source]

Gets the list webview urlname for the model.

Return type:

str

Returns:

The list webview urlname for the model.

classmethod get_table_web_url_name()[source]

Gets the list webview urlname for the model.

Return type:

str

Returns:

The list webview urlname for the model.

classmethod get_detail_web_url_name()[source]

Gets the detail webview urlname for the model.

Return type:

str

Returns:

The detail webview urlname for the model.

classmethod get_edit_web_url_name()[source]

Gets the edit webview urlname for the model.

Return type:

str

Returns:

The edit webview urlname for the model.

class core.mixins.UploadMixin[source]

Bases: object

Mixin providing url methods for the upload page of the model.

classmethod get_upload_web_url_name()[source]

Gets the edit webview urlname for the model.

Return type:

str

Returns:

The edit webview urlname for the model.

get_absolute_upload_url()[source]

Gets the upload webview url for the model instance.

Return type:

str

Returns:

The upload webview url for the model instance.

Parameters:

self (Uploadable)

Submodules