Textlab API

Apps

class integreat_cms.textlab_api.apps.TextlabApiConfig(app_name, app_module)[source]

Bases: AppConfig

Textlab api config inheriting the django AppConfig

__init__(app_name, app_module)[source]
classmethod create(entry)[source]

Factory that creates an app config from an entry in INSTALLED_APPS.

default_auto_field[source]
get_model(model_name, require_ready=True)[source]

Return the model with the given case-insensitive model_name.

Raise LookupError if no model exists with this name.

get_models(include_auto_created=False, include_swapped=False)[source]

Return an iterable of models.

By default, the following models aren’t included:

  • auto-created models for many-to-many relations without an explicit intermediate table,

  • models that have been swapped out.

Set the corresponding keyword argument to True to include such models. Keyword arguments aren’t documented; they’re a private API.

import_models()[source]
name: Final[str] = 'integreat_cms.textlab_api'[source]

Full Python path to the application

ready() None[source]

Checking if api is available

Return type:

None

verbose_name: Final[Promise] = 'TextLab API'[source]

Human-readable name for the application

Textlab API Client

class integreat_cms.textlab_api.textlab_api_client.TextlabClient(username: str, password: str)[source]

Bases: object

Client for the textlab api. Supports login and hix-score retrieval.

A detailed API documentation can be found at https://comlab-ulm.github.io/swagger-V8/

Parameters:
  • username (str) –

  • password (str) –

__init__(username: str, password: str) None[source]
Parameters:
  • username (str) –

  • password (str) –

Return type:

None

benchmark(text: str, text_type: int = 420) float | None[source]

Retrieves the hix score of the given text.

Parameters:
  • text (str) – The text to calculate the score for

  • text_type (int) – The id of the text type (“Textsorte”) or, in terms of the api, benchmark to query. A benchmark is a pre-defined set of modules producing various metrics. They can have threshold/target values, depending on the type of text the benchmark is trying to represent. The available text types activated for the logged in account can be queried by sending a simple GET request to the /benchmark endpoint, complete with all metrics that get included for it. You can find the not so helpful API “documentation” here: https://comlab-ulm.github.io/swagger-V8/ But since for now we are only interested in the HIX score anyway, we just use the benchmark “Letter Demo Integreat” with ID 420 by default.

Returns:

The score, or None if an error occurred

Return type:

float | None

login() None[source]

Authorizes for the textlab api. On success, sets the token attribute.

Raises:

urllib.error.HTTPError – If the login was not successful

Return type:

None

static post_request(path: str, data: dict[str, str], auth_token: str | None = None) dict[str, Any][source]

Sends a request to the api.

Parameters:
  • path (str) – The api path

  • data (dict[str, str]) – The data to send

  • auth_token (str | None) – The authorization token to use

Returns:

The response json dictionary

Raises:

urllib.error.HTTPError – If the request failed

Return type:

dict[str, Any]

Utils

This module contains helpers for the TextLab API client

integreat_cms.textlab_api.utils.check_hix_score(request: HttpRequest, source_translation: EventTranslation | PageTranslation | POITranslation, show_message: bool = True) bool[source]

Check whether the required HIX score is met and it is not ignored

Parameters:
Returns:

Whether the HIX constraints are valid

Return type:

bool