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(perms: PermWrapper) → bool[source]

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

Parameters:

perms (PermWrapper) – Permission of the user

Returns:

Whether the MT section should be shown

Return type:

bool

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 Place).

integreat_cms.cms.templatetags.content_filters.as_weekday_iterator(opening_hours: list[dict[str, Any]]) → Iterable[tuple[str, dict[str, Any]]][source]

This tag returns the opening hours as a dictionary with weekday names as keys.

Parameters:

opening_hours (list[dict[str, Any]])

Return type:

Iterable[tuple[str, dict[str, Any]]]

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_machine_translation_task_id(instance: AbstractContentModel, language_slug: str, mt_task_ids: dict[ObjectIdAndLanguageSlug, str | None] | None = None) → str | None[source]

This tag returns the id of the Celery task currently machine-translating the requested content object into the requested language, if any. Works whether or not a translation already exists for that language.

Parameters:
Returns:

The task id, or None if no machine translation is in progress

Return type:

str | 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.places.place_translation.PlaceTranslation

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.places.place_translation.PlaceTranslation

Return type:

AbstractContentTranslation | None

integreat_cms.cms.templatetags.content_filters.get_translation_state(instance: AbstractContentModel, language_slug: str, mt_task_ids: dict[ObjectIdAndLanguageSlug, str | None] | None = None) → str[source]

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

Parameters:
Returns:

The translation state

Return type:

str

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 Place 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.places.place_translation.PlaceTranslation

Raises:

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

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.translate_language_name(english_name: str) → str[source]

This filter translates an English language name to the current backend language.

Parameters:

english_name (str) – The English name of a language

Returns:

The translated name of the language

Return type:

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

Hix Pages

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

Pages Outdated Or Missing Translation

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_attachments(page_content: str) → str[source]

This tag returns the page content without rel attributes.

WeasyPrint embeds the target of <a rel="attachment"> links as file into the PDF, which must not be controllable via the page content. This filter has to be the last one before the content is marked as safe, and in contrast to the other filters it does not unescape its result, because this would turn escaped markup in the text into real elements again.

Parameters:

page_content (str) – The content of the page

Returns:

The content without rel attributes

Return type:

str

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

Place Filters

This is a collection of tags and filters for places (Place).

integreat_cms.cms.templatetags.place_filters.place_translation_title(place: Place, language: Language) → str[source]

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

Parameters:
  • place (Place) – The requested place

  • language (Language) – The requested language

Returns:

The title of the requested translation

Return type:

str

integreat_cms.cms.templatetags.place_filters.render_place_address(place: Place) → SafeString[source]

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

Parameters:

place (Place) – The requested place

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

Sort Tags

integreat_cms.cms.templatetags.sort_tags.sort_link(context: RequestContext, label: str, field: str) → str[source]

Sets the correct href for sortable table headers

Usage in template:

{% sort_link “Name” “name” %}

Parameters:
  • context (RequestContext)

  • label (str)

  • field (str)

Return type:

str

Svg Tags

Contains a collection of tags for working with svg icons.

integreat_cms.cms.templatetags.svg_tags.get_svg_icon(svg: str) → str[source]

This tags inserts the link to an svg icon

Parameters:

svg (str) – The svg icon to insert

Returns:

The full url of the svg

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]