Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unescape text sent to Textlab API #1808

Merged
merged 1 commit into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
UNRELEASED
----------

* [ [#1808](https://github.com/digitalfabrik/integreat-cms/issues/1808) ] Improve calculation of HIX values via Textlab
* [ [#1800](https://github.com/digitalfabrik/integreat-cms/issues/1800) ] Exclude archived pages from PDF exports
* [ [#1802](https://github.com/digitalfabrik/integreat-cms/issues/1802) ] Reenable table of contents and page numbers in PDFs
* [ [#1350](https://github.com/digitalfabrik/integreat-cms/issues/1350) ] Various small PDF export improvements
Expand Down
8 changes: 6 additions & 2 deletions integreat_cms/textlab_api/textlab_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from urllib.error import HTTPError
from urllib.request import Request, urlopen

from html import unescape

from django.conf import settings
from django.core.exceptions import ImproperlyConfigured

Expand Down Expand Up @@ -48,7 +50,7 @@ def benchmark(self, text):

:raises urllib.error.HTTPError: if an http error occurred
"""
data = {"text": text, "locale_name": "de_DE"}
data = {"text": unescape(text), "locale_name": "de_DE"}
path = "/benchmark/5"
try:
response = self.post_request(path, data, self.token)
Expand Down Expand Up @@ -76,7 +78,9 @@ def post_request(path, data, auth_token=None):
:raises urllib.error.HTTPError: If the request failed
"""
data = json.dumps(data).encode("utf-8")
request = Request(f"{settings.TEXTLAB_API_URL}{path}", data=data, method="POST")
request = Request(
f"{settings.TEXTLAB_API_URL.rstrip('/')}{path}", data=data, method="POST"
)
if auth_token:
request.add_header("authorization", f"Bearer {auth_token}")
request.add_header("Content-Type", "application/json")
Expand Down