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.
- 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.
- 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.MT_SUPPORTED_LOCK_TYPES = {'Page': <class 'integreat_cms.cms.models.pages.page.Page'>}[source]
The heartbeat endpoint handles all content types, but MT progress checking is currently only supported for pages. This maps the content type string (
type(self).__name__fromAbstractContentModel.edit_lock_key) to its model class, acting as an allowlist — types not listed here skip the MT check entirely.{'Page': <class 'integreat_cms.cms.models.pages.page.Page'>}
- 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)
- 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)
- 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:
ExceptionHelper exception used for stopping @lru_cache from caching
- integreat_cms.cms.views.utils.hix.get_hix_score(request: HttpRequest, **kwargs: Any) JsonResponse[source]
Calculates the hix score for the param ‘text’ in the request body and returns it.
- Parameters:
request (HttpRequest) – The request
kwargs (Any)
- 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:
Machine Translation Progress
This module contains the API call handler for polling the progress of an asynchronous machine translation Celery task.
- integreat_cms.cms.views.utils.machine_translation_progress.get_machine_translation_task_progress(request: HttpRequest, region_slug: str, model_type: Literal['page', 'event', 'place', 'pushnotification'], task_id: str) JsonResponse[source]
Report the current progress of an asynchronous machine translation Celery task, identified directly by its task id. Used by callers (e.g. the content list views) that already know which task governs a whole batch of objects, because the task id was resolved once at render time and grouped client-side. Every object in that batch shares the same task, so checking the task once is equivalent to - and cheaper than - checking each object.
- Parameters:
- Returns:
A JSON object describing the current translation progress
- Return type:
JsonResponse
Machine Translation Report
This module contains the AJAX call for reading the machine translation report(s) queued for the current user, region, and content type.
- integreat_cms.cms.views.utils.machine_translation_report.get_machine_translation_report(request: HttpRequest, region_slug: str, language_slug: str, model_type: str) JsonResponse[source]
Report the machine translation report(s) queued for the current user, region, and content type, if any - a destructive read, so each report is only ever returned once, to whoever triggered the translation.
- Parameters:
request (HttpRequest) – The current request
region_slug (str) – The slug of the current region
language_slug (str) – The slug of the current language (unused, kept for URL consistency with the other machine translation AJAX endpoints)
model_type (str) – The content type the reports concern (e.g. “page”)
- Returns:
A JSON object containing the queued reports, if any
- Return type:
JsonResponse
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', 'place']) JsonResponse[source]
This function collects the hix score and the amount of words per content entry from the source
- Parameters:
- 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
Opening Hour
Publication Status
This file contains the helper function to change the publication status of translations
Search Content Ajax
- 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 places, 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:
- 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', 'place']) JsonResponse[source]
checks the current user input for title and generates unique slug for permalink
- Parameters:
- Returns:
unique translation slug
- Raises:
PermissionDenied – If the user does not have the permission to access this function
Http404 – If the given
model_idis invalid or does not exist in the current region
- Return type:
JsonResponse