Utils

Contact Utils

integreat_cms.cms.views.utils.contact_utils.get_contact(request: HttpRequest, contact_id: int, region_slug: str | None = None) str[source]

Retrieves the rendered HTML representation of a contact.

Parameters:
  • request (HttpRequest) – The current request

  • contact_id (int) – The ID of the contact to retrieve

  • region_slug (str | None) – The slug of the current region

Returns:

HTML representation of the requested contact

Return type:

str

integreat_cms.cms.views.utils.contact_utils.get_contact_raw(request: HttpRequest, contact_id: int, region_slug: str | None = None) str[source]

Retrieves the short representation of a single contact, and returns it in the same format as a contact search single completion.

Parameters:
  • request (HttpRequest) – The current request

  • contact_id (int) – The ID of the contact to retrieve

  • region_slug (str | None) – The slug of the current region

Returns:

Short representation of the requested contact

Return type:

str

integreat_cms.cms.views.utils.contact_utils.search_contact_ajax(request: HttpRequest, region_slug: str | None = None) JsonResponse[source]

Searches contacts that match the search query.

Parameters:
  • request (HttpRequest) – The current request

  • region_slug (str | None) – The slug of the current region

Raises:

PermissionDenied – If the user has no permission to the object type

Returns:

Json object containing all matching elements, of shape {title: str, url: str, type: str}

Return type:

JsonResponse

Content Edit Lock

integreat_cms.cms.views.utils.content_edit_lock.content_edit_lock_heartbeat(request: HttpRequest, region_slug: str | None = None) JsonResponse[source]

This function handles heartbeat requests. When a heartbeat is received, this function tries to extend the lock for a user who is editing some content.

Parameters:
  • request (HttpRequest) – The current request

  • region_slug (str | None) – The slug of the current region, unused

Returns:

Json object containing success: true if the lock could be acquired

Return type:

JsonResponse

integreat_cms.cms.views.utils.content_edit_lock.content_edit_lock_release(request: HttpRequest, region_slug: str | None = None) JsonResponse[source]

This function handles unlock requests

Parameters:
  • request (HttpRequest) – The current request

  • region_slug (str | None) – The slug of the current region, unused

Returns:

Json object containing success: true if the content object could be unlocked

Return type:

JsonResponse

Hix

This file contains functionality to communicate with the Textlab api to get the hix-value for a given text.

exception integreat_cms.cms.views.utils.hix.CacheMeIfYouCan[source]

Bases: Exception

Helper exception used for stopping @lru_cache from caching

integreat_cms.cms.views.utils.hix.get_hix_score(request: HttpRequest, region_slug: str) JsonResponse[source]

Calculates the hix score for the param ‘text’ in the request body and returns it.

Parameters:
  • request (HttpRequest) – The request

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

Returns:

A json response, of {“score”: value} in case of success

Return type:

JsonResponse

integreat_cms.cms.views.utils.hix.get_translation_over_hix_threshold(region: Region) QuerySet[source]

Filter page translations which are over the hix threshold

Parameters:

region (Region) – The region for which to get all of the translations

Return type:

QuerySet

integreat_cms.cms.views.utils.hix.get_translation_under_hix_threshold(region: Region) QuerySet[source]

Filter page translations which are under the hix threshold

Parameters:

region (Region) – The region for which to get all of the translations

Return type:

QuerySet

integreat_cms.cms.views.utils.hix.get_translations_relevant_to_hix(region: Region) QuerySet[source]

Get page translations for a region sorted by hix score.

Parameters:

region (Region) – The region for which to get all of the translations

Return type:

QuerySet

integreat_cms.cms.views.utils.hix.lookup_hix_score(text: str) TextlabResult | None[source]

This function returns the hix score for the given text. It either performs an api request or returns the value from cache.

Parameters:

text (str) – The text to calculate the hix score for

Returns:

The score for the given text

Return type:

TextlabResult | None

integreat_cms.cms.views.utils.hix.lookup_hix_score_helper(text: str) TextlabResult[source]

This function returns the hix score for the given text. It either performs an api request or returns the value from cache, unless it is None, in which case an exception is raised to prevent caching.

Parameters:

text (str) – The text to calculate the hix score for

Returns:

The score for the given text

Return type:

TextlabResult

Machine Translations

This module contains the generalized function to build the AJAX call for the machine translation popup

integreat_cms.cms.views.utils.machine_translations.build_json_for_machine_translation(request: HttpRequest, region_slug: str, language_slug: str, model_type: Literal['page', 'event', 'poi']) JsonResponse[source]

This function collects the hix score and the amount of words per content entry from the source

Parameters:
  • request (HttpRequest) – The current request

  • region_slug (str) – slug of the according region

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

  • model_type (Literal['page', 'event', 'poi']) – The according model to the different content types

Returns:

A dictionary that contains the data for the machine translation popup (page id, title, amount of words and optional hix value)

Return type:

JsonResponse

Publication Status

This file contains the helper function to change the publication status of translations

integreat_cms.cms.views.utils.publication_status.change_publication_status(request: HttpRequest, selected_content: QuerySet, language_slug: str, desired_status: str) None[source]

Helper function to change the publication status

Parameters:
  • request (HttpRequest) – The current request

  • selected_content (QuerySet) – The current queryset

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

  • desired_status (str) – The desired status

Return type:

None

Search Content Ajax

integreat_cms.cms.views.utils.search_content_ajax.format_object_translation(object_translation: AbstractContentTranslation, typ: Literal['page', 'event', 'poi'], target_language_slug: str) dict[source]

Formats the [poi/event/page]-translation as json

Parameters:
  • object_translation (AbstractContentTranslation) – A translation object which has a title and a permalink

  • typ (Literal['page', 'event', 'poi']) – The type of this object

  • target_language_slug (str) – The slug that the object translation should ideally have

Returns:

A dictionary with the title, path, url and type of the translation object

Return type:

dict

integreat_cms.cms.views.utils.search_content_ajax.search_content_ajax(request: HttpRequest, region_slug: str | None = None, language_slug: str | None = None) JsonResponse[source]

Searches all pois, events and pages for the current region and returns all that match the search query. Results which match the query in the title or slug get ranked higher than results which only match through their text content.

Parameters:
  • request (HttpRequest) – The current request

  • region_slug (str | None) – The slug of the current region

  • language_slug (str) – language slug

Raises:
  • PermissionDenied – If the user has no permission to the object type

  • AttributeError – If the request contains an object type which is unknown or if the user has no permission for it

Returns:

Json object containing all matching elements, of shape {title: str, url: str, type: str}

Return type:

JsonResponse

Slugify Ajax

integreat_cms.cms.views.utils.slugify_ajax.slugify_ajax(request: HttpRequest, region_slug: str, language_slug: str, model_type: Literal['page', 'event', 'poi']) JsonResponse[source]

checks the current user input for title and generates unique slug for permalink

Parameters:
  • request (HttpRequest) – The current request

  • region_slug (str) – region identifier

  • language_slug (str) – language slug

  • model_type (Literal['page', 'event', 'poi']) – The type of model to generate a unique slug for, one of event|page|poi

Returns:

unique translation slug

Raises:

PermissionDenied – If the user does not have the permission to access this function

Return type:

JsonResponse