Textlab API
Apps
- class integreat_cms.textlab_api.apps.TextlabApiConfig(app_name, app_module)[source]
Bases:
AppConfig
Textlab api config inheriting the django AppConfig
- classmethod create(entry)[source]
Factory that creates an app config from an entry in INSTALLED_APPS.
- 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.
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/
- benchmark(text: str, text_type: int = 420) TextlabResult [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 ID420
by default.
- Returns:
The textlab result including score and feedback, or None if an error occurred
- Return type:
- 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
- class integreat_cms.textlab_api.textlab_api_client.TextlabResult[source]
Bases:
TypedDict
The result that is returned from the textlab api via benchmark.
- fromkeys(value=None, /)[source]
Create a new dictionary with keys from iterable and values set to value.
- get(key, default=None, /)[source]
Return the value for key if key is in the dictionary, else default.
- pop(k[, d]) v, remove specified key and return the corresponding value. [source]
If the key is not found, return the default if given; otherwise, raise a KeyError.
- popitem()[source]
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
- setdefault(key, default=None, /)[source]
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
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:
request (HttpRequest) – The current request
source_translation (EventTranslation | (PageTranslation | POITranslation)) – The source translation
show_message (bool) – whether the massage should be shown to users.
- Returns:
Whether the HIX constraints are valid
- Return type:
- integreat_cms.textlab_api.utils.dict_path(data: dict, path: list[str]) Any [source]
Resolves a path in the given data dictionary and returns the value :param data: The data dictionary to get the value from :param path: The path to lookup :return: The result of the lookup in the dictionary