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
language_color (CharField) –
Language color. This color is used to represent the color label of the chosen language
Manage choices in
language_color
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.
social_media_webapp_title (CharField) – Social media title of the WebApp. Displayed title of the WebApp in the search results and on social media pages (max 100 characters).
social_media_webapp_description (TextField) – Social media description. Displayed description of the WebApp in the search results and on social media pages (max 200 characters).
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:
chats (Reverse
ForeignKey
fromUserChat
) – All chats of this language (related name oflanguage
)event_translations (Reverse
ForeignKey
fromEventTranslation
) – All event translations of this language (related name oflanguage
)page_translations (Reverse
ForeignKey
fromPageTranslation
) – All page translations of this language (related name oflanguage
)poi_translations (Reverse
ForeignKey
fromPOITranslation
) – All poi translations of this language (related name oflanguage
)feedback (Reverse
ForeignKey
fromFeedback
) – All feedback of this language (related name oflanguage
)imprint_translations (Reverse
ForeignKey
fromImprintPageTranslation
) – All imprint translations of this language (related name oflanguage
)language_tree_nodes (Reverse
ForeignKey
fromLanguageTreeNode
) – All language tree nodes of this language (related name oflanguage
)poi_category_translations (Reverse
ForeignKey
fromPOICategoryTranslation
) – All poi category translations of this language (related name oflanguage
)push_notification_translations (Reverse
ForeignKey
fromPushNotificationTranslation
) – All push notification translations of this language (related name oflanguage
)
- exception DoesNotExist[source]
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned[source]
Bases:
MultipleObjectsReturned
- active_in_regions[source]
Returns regions in which the language is active
- Returns:
regions in which the language is active
- 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
- can_be_pdf_exported[source]
Returns whether PDF export is allowed for the language
- Returns:
whether PDF export is allowed for the language
- chats[source]
Type: Reverse
ForeignKey
fromUserChat
All chats of this language (related name of
language
)
- 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
- event_translations[source]
Type: Reverse
ForeignKey
fromEventTranslation
All event translations of this language (related name of
language
)
- feedback[source]
Type: Reverse
ForeignKey
fromFeedback
All feedback of this language (related name of
language
)
- 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_language_color_display(*, field=<django.db.models.CharField: language_color>)[source]
Shows the label of the
language_color
. Seeget_FOO_display()
for more information.
- classmethod get_model_name_plural() str [source]
Get the plural representation of this model name
- Returns:
The plural model name
- Return type:
- get_next_by_created_date(*, field=<django.db.models.DateTimeField: created_date>, is_next=True, **kwargs)[source]
Finds next instance based on
created_date
. Seeget_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
. Seeget_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
. Seeget_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
. Seeget_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
. Seeget_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:
- get_secondary_country_code_display(*, field=<django.db.models.CharField: secondary_country_code>)[source]
Shows the label of the
secondary_country_code
. Seeget_FOO_display()
for more information.
- get_text_direction_display(*, field=<django.db.models.CharField: text_direction>)[source]
Shows the label of the
text_direction
. Seeget_FOO_display()
for more information.
- id[source]
Type:
BigAutoField
Primary key: ID
- imprint_translations[source]
Type: Reverse
ForeignKey
fromImprintPageTranslation
All imprint translations of this language (related name of
language
)
- language_color[source]
Type:
CharField
Language color. This color is used to represent the color label of the chosen language
Choices:
#FFBB78
#2CA02C
#FF9896
#C5B0D5
#FF4500
#FFA500
#17157D
#1F77B4
#FFD700
#008080
and 33 more
Manage choices in
language_color
- language_tree_nodes[source]
Type: Reverse
ForeignKey
fromLanguageTreeNode
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.
- page_translations[source]
Type: Reverse
ForeignKey
fromPageTranslation
All page translations of this language (related name of
language
)
- poi_category_translations[source]
Type: Reverse
ForeignKey
fromPOICategoryTranslation
All poi category translations of this language (related name of
language
)
- poi_translations[source]
Type: Reverse
ForeignKey
fromPOITranslation
All poi translations of this language (related name of
language
)
- 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 165 more
Manage choices in
countries
- push_notification_translations[source]
Type: Reverse
ForeignKey
fromPushNotificationTranslation
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 165 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.
- social_media_webapp_description[source]
Type:
TextField
Social media description. Displayed description of the WebApp in the search results and on social media pages (max 200 characters).
- social_media_webapp_title[source]
Type:
CharField
Social media title of the WebApp. Displayed title of the WebApp in the search results and on social media pages (max 100 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
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-treebeard <https://django-treebeard.readthedocs.io/en/latest/>.
- Parameters:
id (BigAutoField) – Primary key: ID
lft (PositiveIntegerField) – Lft
rgt (PositiveIntegerField) – Rgt
tree_id (PositiveIntegerField) – Tree id
depth (PositiveIntegerField) – Depth
visible (BooleanField) – Visible. Defines whether the language is displayed to the users of the app
active (BooleanField) – Active. Defined if content in this language can be created or edited
created_date (DateTimeField) – Creation date
last_updated (DateTimeField) – Modification date
machine_translation_enabled (BooleanField) – Machine translatable. Enable or disable machine translations into this language
preferred_mt_provider (CharField) – Machine translation provider. Preferred provider for translations into this language
Relationship fields:
- Parameters:
parent (
ForeignKey
toLanguageTreeNode
) – Source language (related name:children
)region (
ForeignKey
toRegion
) – Region (related name:language_tree_nodes
)language (
ForeignKey
toLanguage
) – Language (related name:language_tree_nodes
)
Reverse relationships:
- Parameters:
children (Reverse
ForeignKey
fromLanguageTreeNode
) – All children of this language tree node (related name ofparent
)
- exception DoesNotExist[source]
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned[source]
Bases:
MultipleObjectsReturned
- 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:
- 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:
- 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
- children[source]
Type: Reverse
ForeignKey
fromLanguageTreeNode
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
- 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
- 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
- get_cached_ancestors(include_self: bool = False) list[Self] [source]
Get the cached ancestors of a specific node
- get_cached_descendants(include_self: bool = False) list[Self] [source]
Get the cached descendants of a specific node
- 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:
action – read or write
- Returns:
postgresql, mysql or sqlite
- 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.
- 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
- 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:
- get_next_by_created_date(*, field=<django.db.models.DateTimeField: created_date>, is_next=True, **kwargs)[source]
Finds next instance based on
created_date
. Seeget_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
. Seeget_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
. Seeget_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
. Seeget_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
. Seeget_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
- classmethod get_region_tree(region_slug: str) NS_NodeQuerySet [source]
Get the tree of a specific region
- 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:
- 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, returnsFalse
- 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, returnsFalse
- is_sibling_of(node)[source]
- Returns:
True
if the node is a sibling of another node given as an argument, else, returnsFalse
- Parameters:
node – The node that will be checked as a sibling
- language[source]
Type:
ForeignKey
toLanguage
Language (related name:
language_tree_nodes
)
- 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:
InvalidPosition – If the node is moved to another region
DBMutexError – If the DB mutex could not be retrieved
DBMutexTimeoutError – If waiting for the DB mutex timed out
- 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
- parent[source]
Type:
ForeignKey
toLanguageTreeNode
Source language (related name:
children
)
- preferred_mt_provider[source]
Type:
CharField
Machine translation provider. Preferred provider for translations into this language
Choices:
DeepL
Google Translate
SUMM.AI
- 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
toRegion
Region (related name:
language_tree_nodes
)
- 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
- 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