Templatetags

Template tags are our custom extension of the Built-in template tags and filters of The Django template language.

Tags are used to provide arbitrary logic in the rendering process and are surrounded by {% and %}. Filters transform the values of variables and are surrounded by {{ and }}.

See How to create custom template tags and filters for more information.

Arithmetic

integreat_cms.cms.templatetags.arithmetic.diff(value: int, arg: int) int[source]

subtract arg from value

Parameters:
  • value (int) – origin value

  • arg (int) – value to be subtracted

Returns:

result of subtraction

Return type:

int

Base Filters

integreat_cms.cms.templatetags.base_filters.get_mt_visibility(region: Region, perms: PermWrapper) bool[source]

This tag checks whether either DeepL or Google Translate or SUMM.AI is activated in the region and the user has permission to manage automatic translations.

Parameters:
  • region (Region) – The rcurrent region

  • perms (PermWrapper) – Permission of the user

Returns:

Whether the MT section should be shown

Return type:

bool

integreat_cms.cms.templatetags.base_filters.get_private_member(element: LanguageTreeNodeForm | PageForm, key: SafeString) BoundField[source]

This filter returns a private member of an element

Parameters:
  • element (LanguageTreeNodeForm | PageForm) – The requested object

  • key (SafeString) – The key of the private variable (without the leading underscore)

Returns:

The value of the private variable

Return type:

BoundField

integreat_cms.cms.templatetags.base_filters.in_list(value: str | None, comma_separated_list: SafeString) bool[source]

This filter checks whether a given string value is contained in a comma separated list

Parameters:
  • value (str | None) – The value which should be checked

  • comma_separated_list (SafeString) – The list of comma-separated strings

Returns:

Whether or not value is contained in the list

Return type:

bool

Content Filters

This is a collection of tags and filters which are useful for all content types (Page, Event and POI).

integreat_cms.cms.templatetags.content_filters.build_url(target: SafeString, region_slug: str, language_slug: str, content_field: SafeString | str | None = None, content_id: int | None = None) str[source]

This tag returns the requested language by slug

Parameters:
  • target (SafeString) – The slug of the requested target

  • region_slug (str) – The slug of the requested region

  • language_slug (str) – The slug of the requested language

  • content_field (SafeString | str | None) – The name of the content field

  • content_id (int | None) – The id of the content

Returns:

list of args

Return type:

str

integreat_cms.cms.templatetags.content_filters.get_int_list(data: QueryDict, list_name: str) list[int][source]

This filter returns the list data of a one-to-many field as ints.

Parameters:
  • data (QueryDict) – The requested form data

  • list_name (str) – The name of the requested field

Returns:

The int value list

Return type:

list[int]

integreat_cms.cms.templatetags.content_filters.get_language(language_slug: str) Language | None[source]

This tag returns the requested language by slug

Parameters:

language_slug (str) – The slug of the requested language

Returns:

The requested language

Return type:

Language | None

integreat_cms.cms.templatetags.content_filters.get_public_translation(instance: AbstractContentModel, language_slug: str) AbstractContentTranslation | None[source]

This tag returns the most recent public translation of the requested content object in the requested language.

Parameters:
  • instance (AbstractContentModel) – The content object instance

  • language_slug (str) – The slug of the requested language

Returns:

The translation object of the requested instance or ~integreat_cms.cms.models.pois.poi_translation.POITranslation

Return type:

AbstractContentTranslation | None

integreat_cms.cms.templatetags.content_filters.get_translation(instance: AbstractContentModel, language_slug: str) AbstractContentTranslation | None[source]

This tag returns the most recent translation of the requested content object in the requested language.

Parameters:
  • instance (AbstractContentModel) – The content object instance

  • language_slug (str) – The slug of the requested language

Returns:

The translation object of the requested instance or ~integreat_cms.cms.models.pois.poi_translation.POITranslation

Return type:

AbstractContentTranslation | None

integreat_cms.cms.templatetags.content_filters.is_empty(iterable: MultiValueDict) bool[source]

This filter checks whether the given iterable is empty.

Parameters:

iterable (MultiValueDict) – The requested iterable

Returns:

Whether or not the given iterable is empty

Return type:

bool

integreat_cms.cms.templatetags.content_filters.minor_edit_help_text(region: Region, language: Language, translation_form: CustomContentModelForm) Promise[source]

This tag returns the help text of the minor edit field of the given form

Parameters:
Returns:

The minor edit help text

Return type:

Promise

integreat_cms.cms.templatetags.content_filters.minor_edit_label(region: Region, language: Language) Promise[source]

This tag returns the label of the minor edit field of the given form

Parameters:
  • region (Region) – current region

  • language (Language) – The current language

Returns:

The minor edit label

Return type:

Promise

integreat_cms.cms.templatetags.content_filters.object_translation_has_view_perm(user: SimpleLazyObject, obj: AbstractContentTranslation) bool[source]

This filter accepts any translation of Event, Page or Poi and returns whether this account has the permission to view this object

Parameters:
  • user (SimpleLazyObject) – The requested user

  • obj (AbstractContentTranslation) – The requested object ~integreat_cms.cms.models.events.event_translation.EventTranslation, or ~integreat_cms.cms.models.pois.poi_translation.POITranslation

Raises:

ValueError – if the object is not a translation of Event, Page or Poi

Returns:

Whether this account is allowed to view this object

Return type:

bool

integreat_cms.cms.templatetags.content_filters.remove(elements: list[Any], element: Any) list[Any][source]

This tag removes an element from a list.

Parameters:
  • elements (list[Any]) – The given list of elements

  • element (Any) – The element to be removed

Returns:

The list without the element

Return type:

list[Any]

integreat_cms.cms.templatetags.content_filters.sort_translation_states(translation_states: dict[str, tuple[Language, str]], second_language: Language) list[tuple[Language, str]][source]

This filter sorts languages in language tabs

Parameters:
Returns:

the filtered list with the current language on the second position

Return type:

list[tuple[Language, str]]

integreat_cms.cms.templatetags.content_filters.translated_language_name(language_slug: str) str[source]

This tag returns the name of the requested language in the current backend language

Parameters:

language_slug (str) – The slug of the requested language

Returns:

The translated name of the requested language

Return type:

str

Form Icon Filters

integreat_cms.cms.templatetags.form_icon_filters.strip_path(icon: str) str[source]

strips the internal path of the icon file to show user only the file name

Parameters:

icon (str) – relative path inside the media folder

Returns:

name of icon file

Return type:

str

Linkcheck Filters

integreat_cms.cms.templatetags.linkcheck_filters.url_anchor_icon(url: Url) str[source]

Return the icon that represents an URL’s HTML anchor status

Parameters:

url (Url) – The URL

Returns:

The HTML code of the anchor status icon

Return type:

str

integreat_cms.cms.templatetags.linkcheck_filters.url_ssl_icon(url: Url) str[source]

Return the icon that represents an URL’s SSL status

Parameters:

url (Url) – The URL

Returns:

The HTML code of the SSL status icon

Return type:

str

Model Tags

This is a collection of tags and filters which are useful for all models.

integreat_cms.cms.templatetags.model_tags.get_model_verbose_name(instance: AbstractBaseModel) str[source]

This tag returns the readable name of an instance’s model.

Parameters:

instance (AbstractBaseModel) – The model object instance

Returns:

The verbose name of the model

Return type:

str

Page Filters

This is a collection of tags and filters for Page objects.

integreat_cms.cms.templatetags.page_filters.get_depth_in(node: Page, pageset: PageQuerySet) int[source]

This tag returns the depth of node within the tree/pages in pageset.

:param node : the page :param pageset: The pages (all pages or pages chosen by filter) :return: the depth of node within the tree/pages in pageset

Parameters:
Return type:

int

integreat_cms.cms.templatetags.page_filters.get_highest_anscentor_in(node: Page, pageset: PageQuerySet) Page[source]

This tag returns the highest (farthest) ancestor of node within the tree/pages in pageset.

:param node : the page :param pageset: The pages (all pages or pages chosen by filter) :return: the highest (farthest) ancestor of node within the tree/pages in pageset

Parameters:
Return type:

Page

Parse Struct Time

integreat_cms.cms.templatetags.parse_struct_time.parse_struct_time(struct_time: struct_time) date[source]

Converts timestamp to datetime and returns date only

Parameters:

struct_time (struct_time) – timestamp received from rss feed

Returns:

proper parsed date

Return type:

date

PDF Filters

This is a collection of tags and filters for page content used in PDFs (Page).

integreat_cms.cms.templatetags.pdf_filters.pdf_strip_fontstyles(instance: str) str[source]

This tag returns the instance, stripped of inline styling affecting fonts.

Parameters:

instance (str) – The content object instance

Returns:

The instance without inline font styling

Return type:

str

integreat_cms.cms.templatetags.pdf_filters.pdf_truncate_links(page_content: str, max_chars: int) str[source]

This tag returns the page content with truncated link texts.

Parameters:
  • page_content (str) – The content of the page

  • max_chars (int) – The maximal length of a link before it will be truncated

Returns:

The content with truncated links

Return type:

str

POI Filters

This is a collection of tags and filters for points of interest (POI).

integreat_cms.cms.templatetags.poi_filters.poi_translation_title(poi: POI, language: Language) str[source]

This tag returns the title of the most recent translation of the requested point of interest in the requested language.

Parameters:
  • poi (POI) – The requested point of interest

  • language (Language) – The requested language

Returns:

The title of the requested translation

Return type:

str

integreat_cms.cms.templatetags.poi_filters.render_poi_address(poi: POI) SafeString[source]

This tag returns encoded html for the poi address container of this poi

Parameters:

poi (POI) – The requested point of interest

Returns:

An encoded html string

Return type:

SafeString

Push Notification Filters

This is a collection of tags and filters for PushNotification objects.

integreat_cms.cms.templatetags.push_notification_filters.get_translation(push_notification: PushNotification, language_slug: str) PushNotificationTranslation[source]

This tag returns the most recent translation of the requested push notification in the requested language.

Parameters:
  • push_notification (PushNotification) – The requested push notification

  • language_slug (str) – The slug of the requested language

Returns:

The push notification translation

Return type:

PushNotificationTranslation

Settings Tags

This contains tags for accessing settings

integreat_cms.cms.templatetags.settings_tags.get_base_url() str[source]

This tag returns the BASE_URL

Returns:

The base url of the current web application

Return type:

str

integreat_cms.cms.templatetags.settings_tags.get_webapp_url() str[source]

This tag returns the WEBAPP_URL

Returns:

The url of the current web application

Return type:

str

Tagifnotempty

integreat_cms.cms.templatetags.tagifnotempty.tagifnotempty(value: SafeString, args: SafeString) str[source]

Helper function for template to display property if it’s not left empty :param value: url where that is being investigated :param args: properties that might be left empty :return: Correctly formatted properties

Parameters:
Return type:

str

Text Filters

This is a collection of tags and filters for strings.

integreat_cms.cms.templatetags.text_filters.to_json(obj: tuple[int | str, str]) str[source]

Converts the given object to a json string

Parameters:

obj (tuple[int | str, str]) – The input object

Returns:

object as json string

Return type:

str

integreat_cms.cms.templatetags.text_filters.words(text: str) list[str][source]

Split the given text into a list of words, see str.split().

Parameters:

text (str) – The input string

Returns:

The list of words in the text

Return type:

list[str]

Tree Filters

This is a collection of tags and filters for models which inherit from the MPTT model AbstractTreeNode (Page and LanguageTreeNode).

integreat_cms.cms.templatetags.tree_filters.get_children_ids(node: Page) list[int][source]

This filter returns the ids of all the node’s direct children.

Parameters:

node (Page) – The requested node

Returns:

The list of all the node’s children’s ids

Return type:

list[int]

integreat_cms.cms.templatetags.tree_filters.get_descendant_ids(node: LanguageTreeNode | Page) list[int][source]

This filter returns the ids of all the node’s descendants.

Parameters:

node (LanguageTreeNode | Page) – The requested node

Returns:

The list of all the node’s descendants’ ids

Return type:

list[int]

Url Tags

Contains a collection of tags for working with urls.

integreat_cms.cms.templatetags.url_tags.add_queries(url: str, key: str, value: str | int) str[source]

This filter adds a query to an url

Parameters:
  • url (str) – The url to modify

  • key (str) – The key of the querystring

  • value (str | int) – The value of the querystring

Returns:

The url with a modified query part

Return type:

str

integreat_cms.cms.templatetags.url_tags.url_for_current_region(target: str, request: HttpRequest, **kwargs: Any) str[source]

Return the url matching the target url name, region and other supplied slugs

Parameters:
  • target (str) – The name of target url

  • request (HttpRequest) – The current request, used to check whether a region is given or not

  • kwargs (Any) – Other slugs passed as the keyword argument

Return type:

str

User Filters

This is a collection of tags and filters which are useful for all user forms

integreat_cms.cms.templatetags.user_filters.remaining_regions(user: User, region_to_remove: Region) QuerySet[Region][source]

This calculates the remaining regions of a user after a given region is removed

Parameters:
  • user (User) – The given user

  • region_to_remove (Region) – The region which should be removed from the user’s regions

Returns:

The Queryset of regions

Return type:

QuerySet[Region]