Models

This package contains all data models of the Integreat CMS. Please refer to django.db.models for general information about Django models.

Abstract Base Model

class integreat_cms.cms.models.abstract_base_model.AbstractBaseModel(*args, **kwargs)[source]

Bases: Model

Abstract base class for all models

classmethod get_model_name_plural() str[source]

Get the plural representation of this model name

Returns:

The plural model name

Return type:

str

get_repr() str[source]

Returns the canonical string representation of the content object

To be implemented in the inheriting model

Return type:

str

Abstract Content Model

class integreat_cms.cms.models.abstract_content_model.AbstractContentModel(*args, **kwargs)[source]

Bases: AbstractBaseModel

Abstract base class for all content models

Parameters:

created_date (DateTimeField) – Creation date

Relationship fields:

Parameters:

region (ForeignKey to Region) – Region

available_translations() Iterator[Any][source]

This method returns an iterator over all available translations, respecting the fallback_translations_enabled setting.

Returns:

An iterator over all translations

Return type:

Iterator[Any]

backend_edit_link[source]

This function returns the absolute url to the edit form of this region

Returns:

The url

backend_translation[source]

This function returns the translation of this content object in the current backend language.

Returns:

The backend translation of a content object

best_translation[source]

This function returns the translation of this content object in the current backend language and if it doesn’t exist, it provides a fallback to the translation in the region’s default language.

Returns:

The “best” translation of a content object for displaying in the backend

default_public_translation[source]

This function returns the public translation of this content object in the region’s default language.

Returns:

The default translation of a content object

default_translation[source]

This function returns the translation of this content object in the region’s default language. Since a content object can only be created by creating a translation in the default language, this is guaranteed to return a object translation (Exception: When the default language tree node is changed to another language after the page has been created, the default translation might not exist).

Returns:

The default translation of a content object

property edit_lock_key: tuple[str | int | None, str][source]

This property returns the key that is used to lock this specific content object

Returns:

A tuple of the id of this object and the classname

property fallback_translations_enabled: bool[source]

Whether translations should be returned in the default language if they do not exist

Returns:

Whether fallback translations are enabled

get_locking_user() Any | None[source]

This method returns the user that is currently locking this content object.

Returns:

The user

Return type:

Any | None

get_major_public_translation(language_slug: str) AbstractContentTranslation | None[source]

This function retrieves the newest major public translation of a content object.

Parameters:

language_slug (str) – The slug of the requested Language

Returns:

The public translation of a content object

Return type:

AbstractContentTranslation | None

get_major_translation(language_slug: str) AbstractContentTranslation | None[source]

This function retrieves the newest major translation of a content object.

Parameters:

language_slug (str) – The slug of the requested Language

Returns:

The public translation of a content object

Return type:

AbstractContentTranslation | None

get_prefetched_translations_by_language_slug(attr: str = 'prefetched_translations', **filters: Any) dict[str, AbstractContentTranslation][source]

This method returns a mapping from language slugs to their latest translations of this object

Parameters:
  • attr (str) – Which attribute should be tried to get the prefetched translations [optional, defaults to "prefetched_translations"]

  • **filters (Any) – Additional filters to be applied on the translations (e.g. by status)

Returns:

The prefetched translations by language slug

Return type:

dict[str, AbstractContentTranslation]

get_public_or_draft_translation(language_slug: str) AbstractContentTranslation | None[source]

This function retrieves the newest public or draft translation of a content object.

Parameters:

language_slug (str) – The slug of the requested Language

Returns:

The public translation of a content object

Return type:

AbstractContentTranslation | None

get_public_translation(language_slug: str) AbstractContentTranslation | None[source]

This function retrieves the newest public translation of a content object.

Parameters:

language_slug (str) – The slug of the requested Language

Returns:

The public translation of a content object

Return type:

AbstractContentTranslation | None

get_repr() str[source]

This overwrites the default Django __repr__() method which would return <AbstractContentModel: AbstractContentModel object (id)>. It is used for logging.

Returns:

The canonical string representation of the content object

Return type:

str

get_translation(language_slug: str) AbstractContentTranslation | None[source]

This function uses the reverse foreign key self.translations to get all translations of self and filters them to the requested Language slug.

Parameters:

language_slug (str) – The slug of the desired Language

Returns:

The translation in the requested Language or None if no translation exists

Return type:

AbstractContentTranslation | None

get_translation_state(language_slug: str) str[source]

This function returns the current state of a translation in the given language.

Parameters:

language_slug (str) – The slug of the desired Language

Returns:

A string describing the state of the translation, one of CHOICES

Return type:

str

hix_ignore: bool = False[source]

Whether the HIX value is ignored (this is False by default if not overwritten by a submodel)

invalidate_cached_translations() None[source]

Delete all cached translations and query them from the database again when they are accessed next time.

This is helpful when new translations have been created and the content model should be reused.

Return type:

None

languages[source]

This property returns a list of all Language objects, to which a translation exists.

Returns:

The existing languages of this content object

objects = <django.db.models.manager.ManagerFromContentQuerySet object>[source]

Django manager to access the ORM Use AbstractContentModel.objects.all() to fetch all objects.

Custom model manager for content objects

prefetched_major_public_translations_by_language_slug[source]

This method returns a mapping from language slugs to their major public translations of this object

Returns:

The object translation in the requested Language or None if no translation exists

prefetched_major_translations_by_language_slug[source]

This method returns a mapping from language slugs to their major translations of this object

Returns:

The object translation in the requested Language or None if no translation exists

prefetched_public_or_draft_translations_by_language_slug[source]

This method returns a mapping from language slugs to their public translations of this object

Returns:

The object translation in the requested Language or None if no translation exists

prefetched_public_translations_by_language_slug[source]

This method returns a mapping from language slugs to their public translations of this object

Returns:

The object translation in the requested Language or None if no translation exists

prefetched_translations_by_language_slug[source]

This method returns a mapping from language slugs to their latest translations of this object

Returns:

The prefetched translations by language slug

public_languages[source]

This property returns a list of all Language objects, to which a public translation exists and which are visible in this region.

Returns:

The existing languages of this content object

translation_states[source]

This property calculates all translations states of the object

Returns:

A dictionary containing each language as key and the given translation state as value

class integreat_cms.cms.models.abstract_content_model.ContentQuerySet(model=None, query=None, using=None, hints=None)[source]

Bases: QuerySet

This queryset provides the option to prefetch translations for content objects

prefetch_major_public_translations() ContentQuerySet[source]

Get the queryset including the custom attribute prefetched_major_public_translations which contains the latest major (in other words not a minor edit) public translations of each content object in each language

Returns:

The queryset of content objects

Return type:

ContentQuerySet

prefetch_major_translations() ContentQuerySet[source]

Get the queryset including the custom attribute prefetched_major_translations which contains the latest major (in other words not a minor edit) translations of each content object in each language

Returns:

The queryset of content objects

Return type:

ContentQuerySet

prefetch_public_or_draft_translations() ContentQuerySet[source]

Get the queryset including the custom attribute prefetched_public_or_draft_translations which contains the latest public or draft translations of each content object in each language

Returns:

The queryset of content objects

Return type:

ContentQuerySet

prefetch_public_translations() ContentQuerySet[source]

Get the queryset including the custom attribute prefetched_public_translations which contains the latest public translations of each content object in each language

Returns:

The queryset of content objects

Return type:

ContentQuerySet

prefetch_translations(to_attr: str = 'prefetched_translations', **filters: Any) ContentQuerySet[source]

Get the queryset including the custom attribute to_attr which contains the latest translations of each content object in each language, optionally filtered by the given status

Parameters:
  • to_attr (str) – To which attribute the prefetched translations should be added [optional, defaults to prefetched_translations]

  • **filters (Any) – Additional filters to be applied on the translations (e.g. by status)

Returns:

The queryset of content objects

Return type:

ContentQuerySet

Abstract Content Translation

class integreat_cms.cms.models.abstract_content_translation.AbstractContentTranslation(*args, **kwargs)[source]

Bases: AbstractBaseModel

Data model representing a translation of some kind of content (e.g. pages or events)

Parameters:
  • title (CharField) – Title

  • slug (SlugField) – Link. String identifier without spaces and special characters. Unique per region and language. Leave blank to generate unique parameter from title.

  • status (CharField) –

    Status

    Manage choices in status

  • content (TextField) – Content

  • currently_in_translation (BooleanField) – Currently in translation. Flag to indicate a translation is being updated by an external translator

  • machine_translated (BooleanField) – Machine translated. Flag to indicate whether a translations is machine translated

  • version (PositiveIntegerField) – Revision

  • minor_edit (BooleanField) – Minor edit. Tick if this change does not require an update of translations in other languages.

  • last_updated (DateTimeField) – Modification date

  • automatic_translation (BooleanField) – Automatic translation. Tick if updating this content should automatically refresh or create its translations.

Relationship fields:

Parameters:
all_versions[source]

This property returns all versions of this translation’s page in its language

Returns:

All versions of this translation

available_languages_dict[source]

This property checks in which Language the content is translated apart from self.language It only returns languages which have a public translation, so drafts are not included here. The returned dict has the following format:

{
    available_translation.language.slug: {
        'id': available_translation.id,
        'url': available_translation.permalink
        'path': available_translation.path
    },
    ...
}
Returns:

A dictionary containing the available languages of a content translation

backend_edit_link[source]

Generates the url of the edit page for the content

To be implemented in the inheriting model

base_link[source]

Generates the base link which is the whole url without slug

For information about the components of such an url, see get_absolute_url()

Returns:

the base link of the content

static foreign_field() Literal['page', 'event', 'poi'][source]

The field name of the reference to the foreign object which the translation belongs to

To be implemented in the inheriting model

Return type:

Literal[‘page’, ‘event’, ‘poi’]

foreign_object[source]

Returns the object the translation belongs to This is needed to generalize the slug_utils for all content types

To be implemented in the inheriting model

full_url[source]

This property returns the full url of this content translation object

Returns:

The full url

get_absolute_url() str[source]

Generates the absolute url of the content translation object

Here is an example for demonstrating the components of a page url:

https://integreat.app/augsburg/en/welcome/city-map/attractions/
|-------------------------------------------------------------|    full_url
                     |----------------------------------------|    get_absolute_url()
|-------------------------------------------------|                base_link
                     |----------------------------|                url_prefix
                                 |----------------|                url_infix
                                                  |-----------|    slug

Here is an example for demonstrating the components of an event url:

https://integreat.app/augsburg/en/events/test-event/
|--------------------------------------------------|    full_url
                     |-----------------------------|    get_absolute_url()
|---------------------------------------|               base_link
                     |------------------|               url_prefix
                                 |------|               url_infix
                                        |----------|    slug
Returns:

The absolute url

Return type:

str

get_repr() str[source]

This overwrites the default Django __repr__() method. It is used for logging.

Returns:

The canonical string representation of the content translation

Return type:

str

hix_enabled[source]

This function returns whether the HIX API is enabled for this instance

Returns:

Whether HIX is enabled

hix_ignore[source]

Whether this translation is ignored for HIX calculation

Returns:

Wether the HIX value is ignored

hix_score = None[source]

The HIX score is None if not overwritten by a submodel

hix_sufficient_for_mt[source]

Whether this translation has a sufficient HIX value for machine translations. If it is None, machine translations are allowed by default.

Returns:

Wether the HIX value is sufficient for MT

is_outdated[source]

This property checks whether a translation is outdated and thus needs a new revision of the content. This happens, when the source translation is updated and the update is no minor_edit.

  • If the translation is currently being translated, it is considered not outdated.

  • If the translation’s language is the region’s default language, it is defined to be never outdated.

  • If the translation’s source translation is already outdated, then the translation itself also is.

  • If neither the translation nor its source translation have a latest major public translation, it is defined as not outdated.

  • If neither the translation nor its source translation have a latest major public translation, it is defined as not outdated.

Otherwise, the outdated flag is calculated by comparing the last_updated-field of the translation and its source translation.

Returns:

Flag to indicate whether the translation is outdated

is_up_to_date[source]

This property checks whether a translation is up to date. A translation is considered up to date when it is not outdated and not being translated at the moment.

Returns:

Flag which indicates whether a translation is up to date

latest_version[source]

This property is a link to the most recent version of this translation.

Returns:

The latest revision of the translation

major_public_source_translation[source]

This property returns the latest major public version of the translation which was used to create the self translation. It derives this information from the Region’s root LanguageTreeNode.

Returns:

The content translation in the source Language (None if the translation is in the Region’s default Language)

major_public_version[source]

This property is a link to the most recent major public version of this translation. This is used when translations, which are derived from this translation, check whether they are up to date.

Returns:

The latest major public revision of the translation

major_source_translation[source]

This property returns the latest major version of the translation which was used to create the self translation. It derives this information from the Region’s root LanguageTreeNode.

Returns:

The content translation in the source Language (None if the translation is in the Region’s default Language)

major_version[source]

This property is a link to the most recent major version of this translation. This is used when translations, which are derived from this translation, check whether they are up to date.

Returns:

The latest major public revision of the translation

path() str[source]

This method returns a human-readable path that should uniquely identify this object within a given region If this content object does not have a hierarchy, just str(obj) should suffice

Returns:

The path

Return type:

str

public_or_draft_source_translation[source]

This property returns the public and draft translation which was used to create the self translation. It derives this information from the Region’s root LanguageTreeNode.

Returns:

The content translation in the source Language (None if no public source translation exists)

public_source_translation[source]

This property returns the public translation which was used to create the self translation. It derives this information from the Region’s root LanguageTreeNode.

Returns:

The content translation in the source Language (None if no public source translation exists)

public_version[source]

This property is a link to the most recent public version of this translation. If the translation itself is not public, this property can return a revision which is older than self.

Returns:

The latest public revision of the translation

read_only: bool = False[source]

Whether this object is read-only and not meant to be stored to the database

save(*args: Any, **kwargs: Any) None[source]

This overwrites the default Django save() method, to update the last_updated field on changes.

Parameters:
  • *args (Any) – The supplied arguments

  • **kwargs (Any) – The supplied kwargs

Raises:

RuntimeError – When the object was locked for database writes

Return type:

None

classmethod search(region: Region, language_slug: str, query: str) QuerySet[source]

Searches for all content translations which match the given query in their title or slug. :param region: The current region :param language_slug: The language slug :param query: The query string used for filtering the content translations :return: A query for all matching objects

Parameters:
  • region (Region) –

  • language_slug (str) –

  • query (str) –

Return type:

QuerySet

sitemap_alternates[source]

This property returns the language alternatives of a content translation for the use in sitemaps. Similar to available_languages_dict(), but in a slightly different format.

Returns:

A list of dictionaries containing the alternative translations of a content translation

source_language[source]

This property returns the source language of this language in this Region’s language tree

Returns:

The source language of this translation

source_translation[source]

This property returns the translation which was used to create the self translation. It derives this information from the Region’s root LanguageTreeNode.

Returns:

The content translation in the source Language (None if the translation is in the Region’s default Language)

status[source]

Type: CharField

Status

Choices:

  • DRAFT

  • REVIEW

  • PUBLIC

  • AUTO_SAVE

Manage choices in status

translation_state[source]

This function returns the current state of a translation in the given language.

Returns:

A string describing the state of the translation, one of CHOICES

url_infix[source]

Generates the infix of the url of the content translation object

For information about the components of such an url, see get_absolute_url()

To be implemented in the inheriting model

url_prefix[source]

Generates the prefix of the url of the content translation object

For information about the components of such an url, see get_absolute_url()

Returns:

The prefix to the url

Abstract Tree Node

class integreat_cms.cms.models.abstract_tree_node.AbstractTreeNode(*args, **kwargs)[source]

Bases: NS_Node, AbstractBaseModel

Abstract data model representing a tree node within a region.

Parameters:

Relationship fields:

Parameters:
add_child(**kwargs: Any) AbstractTreeNode[source]

Adds a child to the node

Parameters:

**kwargs (Any) – The supplied keyword arguments

Returns:

The new child

Return type:

AbstractTreeNode

add_sibling(pos: str | None = None, **kwargs: Any) AbstractTreeNode[source]

Adds a new node as a sibling to the current node object

Parameters:
  • pos (str | None) – The position of the new sibling

  • **kwargs (Any) – The supplied keyword arguments

Returns:

The new sibling

Return type:

AbstractTreeNode

cached_children[source]

Get all cached children

Returns:

A list of all the node’s cached children

cached_parent[source]

Get the parent node of the current node object. Caches the result in the object itself to help in loops.

Returns:

The parent of the node

classmethod find_problems() None[source]

Checks for problems in the tree structure.

This dummy method definition exists to silence pylint’s warning: Method ‘find_problems’ is abstract in class ‘Node’ but is not overridden (abstract-method)

Return type:

None

classmethod fix_tree() None[source]

Solves problems that can appear when transactions are not used and a piece of code breaks, leaving the tree in an inconsistent state.

This dummy method definition exists to silence pylint’s warning: Method ‘fix_tree’ is abstract in class ‘Node’ but is not overridden (abstract-method)

Return type:

None

get_cached_ancestors(include_self: bool = False) list[AbstractTreeNode][source]

Get the cached ancestors of a specific node

Parameters:

include_self (bool) – Whether the current node should be included in the result (defaults to False)

Returns:

A QuerySet containing the current node object’s ancestors, starting by the root node and descending to the parent.

Return type:

list[AbstractTreeNode]

get_cached_descendants(include_self: bool = False) list[AbstractTreeNode][source]

Get the cached descendants of a specific node

Parameters:

include_self (bool) – Whether the current node should be included in the result (defaults to False)

Returns:

A QuerySet containing the current node object’s ancestors, starting by the root node and descending to the parent.

Return type:

list[AbstractTreeNode]

classmethod get_region_root_nodes(region_slug: str) NS_NodeQuerySet[source]

Get all root nodes of a specific region

Parameters:

region_slug (str) – The slug of the requested Region

Returns:

A queryset containing the root nodes in the tree.

Return type:

NS_NodeQuerySet

classmethod get_region_tree(region_slug: str) NS_NodeQuerySet[source]

Get the tree of a specific region

Parameters:

region_slug (str) – The slug of the requested Region

Returns:

A QuerySet of nodes ordered as DFS, including the parent.

Return type:

NS_NodeQuerySet

get_repr() str[source]

This overwrites the default Django __repr__() method which would return <AbstractTreeNode: AbstractTreeNode object (id)>. It is used for logging.

Returns:

The canonical string representation of the tree node

Return type:

str

classmethod get_tree(parent: AbstractTreeNode | None = None) NS_NodeQuerySet[source]

Get the tree of a specific parent node

Parameters:

parent (AbstractTreeNode | None) – The parent node of which the tree should be returned (optional, if no parent is given, all trees are returned.)

Returns:

A QuerySet of nodes ordered as DFS, including the parent.

Return type:

NS_NodeQuerySet

get_tree_max_depth(max_depth: int = 1) NS_NodeQuerySet[source]

Return all descendants with depth less or equal to max depth relative to this nodes depth

Parameters:

max_depth (int) – The nodes maximum depth in the tree

Returns:

This node including its descendants with relative max depth

Return type:

NS_NodeQuerySet

move(target: AbstractTreeNode, pos: str | None = None) None[source]

Moves the current node and all it’s descendants to a new position relative to another node.

Parameters:
  • target (AbstractTreeNode) – The target mode which determines the new position

  • pos (str | None) – The new position of the page relative to the target (choices: position)

Raises:
Return type:

None

next_region_sibling[source]

Get the next node’s sibling, or None if it was the rightmost sibling.

Returns:

The next node’s sibling in its region

prev_region_sibling[source]

Get the previous node’s sibling, or None if it was the leftmost sibling.

Returns:

The previous node’s sibling in its region

region_siblings[source]

Get all siblings of a specific node in its region

Returns:

A QuerySet of all the node’s siblings, including the node itself.

Decorators

Django model decorators can be used to modify inherited fields of abstract models.

integreat_cms.cms.models.decorators.modify_fields(**kwargs: Any) Callable[source]

This decorator can be used to override properties of inherited django model fields.

Parameters:

**kwargs (Any) – A mapping from model fields to their overridden key/value pairs

Returns:

The decorated class

Return type:

Callable