Languages

This package contains both language-related data models: Language and LanguageTreeNode

Language

class integreat_cms.cms.models.languages.language.Language(*args, **kwargs)[source]

Bases: AbstractBaseModel

Data model representing a content language.

Parameters:
  • id (BigAutoField) – Primary key: ID

  • slug (SlugField) – Language Slug. Unique string identifier used in URLs without spaces and special characters.

  • bcp47_tag (SlugField) –

    BCP47 Tag. Language identifier without spaces and special characters. This field usually contains a combination of subtags from the IANA Subtag Registry.

    The recommended minimum buffer for bcp47 is 35. It’s unlikely that we have language slugs longer than 8 characters though. See RFC 5646 Section 4.4.1. Registered tags: https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry

  • native_name (CharField) – Native name. The name of the language in this language.

  • english_name (CharField) – Name in English. The name of the language in English.

  • text_direction (CharField) –

    Text direction

    Manage choices in text_directions

  • primary_country_code (CharField) –

    Primary country flag. The country with which this language is mainly associated. This flag is used to represent the language graphically.

    Manage choices in countries

  • secondary_country_code (CharField) –

    Secondary country flag. Another country with which this language is also associated. This flag is used in the language switcher.

    Manage choices in countries

  • created_date (DateTimeField) – Creation date

  • last_updated (DateTimeField) – Modification date

  • table_of_contents (CharField) – “Table of contents” in this language. The native name for “Table of contents” in this language. This is used in exported PDFs.

  • message_content_not_available (CharField) – “This page does not exist in the selected language. It is however available in these languages:” in this language. This is shown to the user when a page is not available in their language.

  • message_partial_live_content_not_available (CharField) – “Part of the page does not exist in the selected language. It is however available in these languages:” in this language. This is shown to the user when the mirrored part of a page is not available in their language.

Reverse relationships:

Parameters:
exception DoesNotExist[source]

Bases: ObjectDoesNotExist

__init__(*args, **kwargs)[source]
add_note()[source]

Exception.add_note(note) – add a note to the exception

args[source]
silent_variable_failure = True[source]
with_traceback()[source]

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception MultipleObjectsReturned[source]

Bases: MultipleObjectsReturned

__init__(*args, **kwargs)[source]
add_note()[source]

Exception.add_note(note) – add a note to the exception

args[source]
with_traceback()[source]

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

__init__(*args, **kwargs)[source]
active_in_regions[source]

Returns regions in which the language is active

Returns:

regions in which the language is active

async adelete(using=None, keep_parents=False)[source]
async arefresh_from_db(using=None, fields=None)[source]
async asave(force_insert=False, force_update=False, using=None, update_fields=None)[source]
bcp47_tag[source]

Type: SlugField

BCP47 Tag. Language identifier without spaces and special characters. This field usually contains a combination of subtags from the IANA Subtag Registry.

The recommended minimum buffer for bcp47 is 35. It’s unlikely that we have language slugs longer than 8 characters though. See RFC 5646 Section 4.4.1. Registered tags: https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry

classmethod check(**kwargs)[source]
clean()[source]

Hook for doing any extra model-wide validation after clean() has been called on every field by self.clean_fields. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.

clean_fields(exclude=None)[source]

Clean all fields and raise a ValidationError containing a dict of all validation errors if any occur.

created_date[source]

Type: DateTimeField

Creation date

date_error_message(lookup_type, field_name, unique_for)[source]
delete(using=None, keep_parents=False)[source]
english_name[source]

Type: CharField

Name in English. The name of the language in English.

event_translations[source]

Type: Reverse ForeignKey from EventTranslation

All event translations of this language (related name of language)

feedback[source]

Type: Reverse ForeignKey from Feedback

All feedback of this language (related name of language)

classmethod from_db(db, field_names, values)[source]
full_clean(exclude=None, validate_unique=True, validate_constraints=True)[source]

Call clean_fields(), clean(), validate_unique(), and validate_constraints() on the model. Raise a ValidationError for any errors that occur.

get_constraints()[source]
get_deferred_fields()[source]

Return a set containing names of deferred fields for this instance.

classmethod get_model_name_plural() str[source]

Get the plural representation of this model name

Returns:

The plural model name

Return type:

str

get_next_by_created_date(*, field=<django.db.models.DateTimeField: created_date>, is_next=True, **kwargs)[source]

Finds next instance based on created_date. See get_next_by_FOO() for more information.

get_next_by_last_updated(*, field=<django.db.models.DateTimeField: last_updated>, is_next=True, **kwargs)[source]

Finds next instance based on last_updated. See get_next_by_FOO() for more information.

get_previous_by_created_date(*, field=<django.db.models.DateTimeField: created_date>, is_next=False, **kwargs)[source]

Finds previous instance based on created_date. See get_previous_by_FOO() for more information.

get_previous_by_last_updated(*, field=<django.db.models.DateTimeField: last_updated>, is_next=False, **kwargs)[source]

Finds previous instance based on last_updated. See get_previous_by_FOO() for more information.

get_primary_country_code_display(*, field=<django.db.models.CharField: primary_country_code>)[source]

Shows the label of the primary_country_code. See get_FOO_display() for more information.

get_repr() str[source]

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

Returns:

The canonical string representation of the language

Return type:

str

get_secondary_country_code_display(*, field=<django.db.models.CharField: secondary_country_code>)[source]

Shows the label of the secondary_country_code. See get_FOO_display() for more information.

get_text_direction_display(*, field=<django.db.models.CharField: text_direction>)[source]

Shows the label of the text_direction. See get_FOO_display() for more information.

id[source]

Type: BigAutoField

Primary key: ID

imprint_translations[source]

Type: Reverse ForeignKey from ImprintPageTranslation

All imprint translations of this language (related name of language)

language_tree_nodes[source]

Type: Reverse ForeignKey from LanguageTreeNode

All language tree nodes of this language (related name of language)

last_updated[source]

Type: DateTimeField

Modification date

message_content_not_available[source]

Type: CharField

“This page does not exist in the selected language. It is however available in these languages:” in this language. This is shown to the user when a page is not available in their language.

message_partial_live_content_not_available[source]

Type: CharField

“Part of the page does not exist in the selected language. It is however available in these languages:” in this language. This is shown to the user when the mirrored part of a page is not available in their language.

native_name[source]

Type: CharField

Native name. The name of the language in this language.

objects = <django.db.models.Manager object>[source]
page_translations[source]

Type: Reverse ForeignKey from PageTranslation

All page translations of this language (related name of language)

property pk[source]
poi_category_translations[source]

Type: Reverse ForeignKey from POICategoryTranslation

All poi category translations of this language (related name of language)

poi_translations[source]

Type: Reverse ForeignKey from POITranslation

All poi translations of this language (related name of language)

prepare_database_save(field)[source]
primary_country_code[source]

Type: CharField

Primary country flag. The country with which this language is mainly associated. This flag is used to represent the language graphically.

Choices:

  • ab

  • ad

  • ae

  • af

  • al

  • am

  • ao

  • ar

  • at

  • au

  • and 164 more

Manage choices in countries

push_notification_translations[source]

Type: Reverse ForeignKey from PushNotificationTranslation

All push notification translations of this language (related name of language)

refresh_from_db(using=None, fields=None)[source]

Reload field values from the database.

By default, the reloading happens from the database this instance was loaded from, or by the read router if this instance wasn’t loaded from any database. The using parameter will override the default.

Fields can be used to specify which fields to reload. The fields should be an iterable of field attnames. If fields is None, then all non-deferred fields are reloaded.

When accessing deferred fields of an instance, the deferred loading of the field will call this method.

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

This overwrites the default Django save() method, to invalidate the cache of the related objects.

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

  • **kwargs (Any) – The supplied kwargs

Return type:

None

save_base(raw=False, force_insert=False, force_update=False, using=None, update_fields=None)[source]

Handle the parts of saving which should be done only once per save, yet need to be done in raw saves, too. This includes some sanity checks and signal sending.

The ‘raw’ argument is telling save_base not to save any parent models and not to do any changes to the values before save. This is used by fixture loading.

secondary_country_code[source]

Type: CharField

Secondary country flag. Another country with which this language is also associated. This flag is used in the language switcher.

Choices:

  • ab

  • ad

  • ae

  • af

  • al

  • am

  • ao

  • ar

  • at

  • au

  • and 164 more

Manage choices in countries

serializable_value(field_name)[source]

Return the value of the field name for this instance. If the field is a foreign key, return the id value instead of the object. If there’s no Field object with this name on the model, return the model attribute’s value.

Used to serialize a field’s value (in the serializer, or form output, for example). Normally, you would just access the attribute directly and not use this method.

slug[source]

Type: SlugField

Language Slug. Unique string identifier used in URLs without spaces and special characters.

table_of_contents[source]

Type: CharField

“Table of contents” in this language. The native name for “Table of contents” in this language. This is used in exported PDFs.

text_direction[source]

Type: CharField

Text direction

Choices:

  • LEFT_TO_RIGHT

  • RIGHT_TO_LEFT

Manage choices in text_directions

translated_name[source]

Returns the name of the language in the current backend language

Returns:

The translated name of the language

unique_error_message(model_class, unique_check)[source]
validate_constraints(exclude=None)[source]
validate_unique(exclude=None)[source]

Check unique constraints on the model and raise ValidationError if any failed.

visible_in_regions[source]

Returns regions in which the language is visible

Returns:

regions in which the language is visible

Language Tree Node

class integreat_cms.cms.models.languages.language_tree_node.LanguageTreeNode(*args, **kwargs)[source]

Bases: AbstractTreeNode

Data model representing a region’s language tree. Each tree node is a single object instance and the whole tree is identified by the root node. The base functionality inherits from the package django-mptt (Modified Preorder Tree Traversal).

Parameters:

Relationship fields:

Parameters:

Reverse relationships:

Parameters:

children (Reverse ForeignKey from LanguageTreeNode) – All children of this language tree node (related name of parent)

exception DoesNotExist[source]

Bases: ObjectDoesNotExist

__init__(*args, **kwargs)[source]
add_note()[source]

Exception.add_note(note) – add a note to the exception

args[source]
silent_variable_failure = True[source]
with_traceback()[source]

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception MultipleObjectsReturned[source]

Bases: MultipleObjectsReturned

__init__(*args, **kwargs)[source]
add_note()[source]

Exception.add_note(note) – add a note to the exception

args[source]
with_traceback()[source]

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

__init__(*args, **kwargs)[source]
active[source]

Type: BooleanField

Active. Defined if content in this language can be created or edited

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

classmethod add_root(**kwargs)[source]

Adds a root node to the tree.

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

async adelete(using=None, keep_parents=False)[source]
async arefresh_from_db(using=None, fields=None)[source]
async asave(force_insert=False, force_update=False, using=None, update_fields=None)[source]
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 check(**kwargs)[source]
children[source]

Type: Reverse ForeignKey from LanguageTreeNode

All children of this language tree node (related name of parent)

clean()[source]

Hook for doing any extra model-wide validation after clean() has been called on every field by self.clean_fields. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.

clean_fields(exclude=None)[source]

Clean all fields and raise a ValidationError containing a dict of all validation errors if any occur.

created_date[source]

Type: DateTimeField

Creation date

date_error_message(lookup_type, field_name, unique_for)[source]
delete(*args, **kwargs)[source]

Removes a node and all it’s descendants.

depth[source]

Type: PositiveIntegerField

Depth

classmethod dump_bulk(parent=None, keep_ids=True)[source]

Dumps a tree branch to a python data structure.

english_name[source]

Returns the name of this node’s language in English

Returns:

The English name of this language 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

classmethod from_db(db, field_names, values)[source]
full_clean(exclude=None, validate_unique=True, validate_constraints=True)[source]

Call clean_fields(), clean(), validate_unique(), and validate_constraints() on the model. Raise a ValidationError for any errors that occur.

get_ancestors()[source]
Returns:

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

classmethod get_annotated_list(parent=None, max_depth=None)[source]

Gets an annotated list from a tree branch.

Parameters:
  • parent – The node whose descendants will be annotated. The node itself will be included in the list. If not given, the entire tree will be annotated.

  • max_depth – Optionally limit to specified depth

classmethod get_annotated_list_qs(qs)[source]

Gets an annotated list from a queryset.

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]

get_children()[source]
Returns:

A queryset of all the node’s children

get_children_count()[source]
Returns:

The number of the node’s children

get_constraints()[source]
classmethod get_database_vendor(action)[source]

returns the supported database vendor used by a treebeard model when performing read (select) or write (update, insert, delete) operations.

Parameters:

actionread or write

Returns:

postgresql, mysql or sqlite

get_deferred_fields()[source]

Return a set containing names of deferred fields for this instance.

get_depth()[source]
Returns:

the depth (level) of the node

get_descendant_count()[source]
Returns:

the number of descendants of a node.

get_descendants()[source]
Returns:

A queryset of all the node’s descendants as DFS, doesn’t include the node itself

classmethod get_descendants_group_count(parent=None)[source]

Helper for a very common case: get a group of siblings and the number of descendants (not only children) in every sibling.

Parameters:

parent – The parent of the siblings to return. If no parent is given, the root nodes will be returned.

Returns:

A list (NOT a Queryset) of node objects with an extra attribute: descendants_count.

get_first_child()[source]
Returns:

The leftmost node’s child, or None if it has no children.

classmethod get_first_root_node()[source]
Returns:

The first root node in the tree or None if it is empty.

get_first_sibling()[source]
Returns:

The leftmost node’s sibling, can return the node itself if it was the leftmost sibling.

classmethod get_foreign_keys()[source]

Get foreign keys and models they refer to, so we can pre-process the data for load_bulk

get_last_child()[source]
Returns:

The rightmost node’s child, or None if it has no children.

classmethod get_last_root_node()[source]
Returns:

The last root node in the tree or None if it is empty.

get_last_sibling()[source]
Returns:

The rightmost node’s sibling, can return the node itself if it was the rightmost sibling.

classmethod get_model_name_plural() str[source]

Get the plural representation of this model name

Returns:

The plural model name

Return type:

str

get_next_by_created_date(*, field=<django.db.models.DateTimeField: created_date>, is_next=True, **kwargs)[source]

Finds next instance based on created_date. See get_next_by_FOO() for more information.

get_next_by_last_updated(*, field=<django.db.models.DateTimeField: last_updated>, is_next=True, **kwargs)[source]

Finds next instance based on last_updated. See get_next_by_FOO() for more information.

get_next_sibling()[source]
Returns:

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

get_parent(update=False)[source]
Returns:

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

get_preferred_mt_provider_display(*, field=<django.db.models.CharField: preferred_mt_provider>)[source]

Shows the label of the preferred_mt_provider. See get_FOO_display() for more information.

get_prev_sibling()[source]
Returns:

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

get_previous_by_created_date(*, field=<django.db.models.DateTimeField: created_date>, is_next=False, **kwargs)[source]

Finds previous instance based on created_date. See get_previous_by_FOO() for more information.

get_previous_by_last_updated(*, field=<django.db.models.DateTimeField: last_updated>, is_next=False, **kwargs)[source]

Finds previous instance based on last_updated. See get_previous_by_FOO() for more information.

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 <LanguageTreeNode: LanguageTreeNode object (id)>. It is used for logging.

Returns:

The canonical string representation of the language node

Return type:

str

get_root()[source]
Returns:

the root node for the current node object.

classmethod get_root_nodes()[source]
Returns:

A queryset containing the root nodes in the tree.

get_siblings()[source]
Returns:

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

get_sorted_pos_queryset(siblings, newobj)[source]
Returns:

A queryset of the nodes that must be moved to the right. Called only for Node models with node_order_by

This function is based on _insertion_target_filters from django-mptt (BSD licensed) by Jonathan Buchanan: https://github.com/django-mptt/django-mptt/blob/0.3.0/mptt/signals.py

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

id[source]

Type: BigAutoField

Primary key: ID

is_child_of(node)[source]
Returns:

True if the node is a child of another node given as an argument, else, returns False

Parameters:

node – The node that will be checked as a parent

is_descendant_of(node)[source]
Returns:

True if the node if a descendant of another node given as an argument, else, returns False

is_leaf()[source]
Returns:

True if the node is a leaf node (else, returns False)

is_root()[source]
Returns:

True if the node is a root node (else, returns False)

is_sibling_of(node)[source]
Returns:

True if the node is a sibling of another node given as an argument, else, returns False

Parameters:

node – The node that will be checked as a sibling

language[source]

Type: ForeignKey to Language

Language (related name: language_tree_nodes)

language_id[source]

Internal field, use language instead.

last_updated[source]

Type: DateTimeField

Modification date

lft[source]

Type: PositiveIntegerField

Lft

classmethod load_bulk(bulk_data, parent=None, keep_ids=False)[source]

Loads a list/dictionary structure to the tree.

machine_translation_enabled[source]

Type: BooleanField

Machine translatable. Enable or disable machine translations into this language

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

mt_provider[source]

Return the preferred machine translation provider if valid, or the first available provider, or None

Returns:

The MT provider for this target language

mt_providers[source]

Return the list of supported machine translation providers

Returns:

The MT provider for this target language

native_name[source]

Returns the native name of this node’s language

Returns:

The native name of this language node

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

node_order_by = [][source]
objects = <treebeard.ns_tree.NS_NodeManager object>[source]
parent[source]

Type: ForeignKey to LanguageTreeNode

Source language (related name: children)

parent_id[source]

Internal field, use parent instead.

property pk[source]
preferred_mt_provider[source]

Type: CharField

Machine translation provider. Preferred provider for translations into this language

Choices:

  • DeepL

  • Google Translate

  • SUMM.AI

prepare_database_save(field)[source]
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

refresh_from_db(using=None, fields=None)[source]

Reload field values from the database.

By default, the reloading happens from the database this instance was loaded from, or by the read router if this instance wasn’t loaded from any database. The using parameter will override the default.

Fields can be used to specify which fields to reload. The fields should be an iterable of field attnames. If fields is None, then all non-deferred fields are reloaded.

When accessing deferred fields of an instance, the deferred loading of the field will call this method.

region[source]

Type: ForeignKey to Region

Region (related name: language_tree_nodes)

region_id[source]

Internal field, use region instead.

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.

rgt[source]

Type: PositiveIntegerField

Rgt

save(force_insert=False, force_update=False, using=None, update_fields=None)[source]

Save the current instance. Override this in a subclass if you want to control the saving process.

The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.

save_base(raw=False, force_insert=False, force_update=False, using=None, update_fields=None)[source]

Handle the parts of saving which should be done only once per save, yet need to be done in raw saves, too. This includes some sanity checks and signal sending.

The ‘raw’ argument is telling save_base not to save any parent models and not to do any changes to the values before save. This is used by fixture loading.

serializable_value(field_name)[source]

Return the value of the field name for this instance. If the field is a foreign key, return the id value instead of the object. If there’s no Field object with this name on the model, return the model attribute’s value.

Used to serialize a field’s value (in the serializer, or form output, for example). Normally, you would just access the attribute directly and not use this method.

slug[source]

Returns the slug of this node’s language

Returns:

The language slug of this language node

text_direction[source]

Returns the text direction (e.g. left-to-right) of this node’s language

Returns:

The text direction name of this language node

translated_name[source]

Returns the name of this node’s language in the current backend language

Returns:

The translated name of this language node

tree_id[source]

Type: PositiveIntegerField

Tree id

unique_error_message(model_class, unique_check)[source]
validate_constraints(exclude=None)[source]
validate_unique(exclude=None)[source]

Check unique constraints on the model and raise ValidationError if any failed.

visible[source]

Type: BooleanField

Visible. Defines whether the language is displayed to the users of the app