Skip to content

Commit

Permalink
Merge pull request #3275 from digitalfabrik/develop
Browse files Browse the repository at this point in the history
Release `2024.12.1`
  • Loading branch information
MizukiTemma authored Dec 11, 2024
2 parents 3df1ef2 + f00b63c commit 4b851bf
Show file tree
Hide file tree
Showing 166 changed files with 554 additions and 434 deletions.
9 changes: 6 additions & 3 deletions docs/src/code-style.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,13 @@ Run pylint with our developer tool :github-source:`tools/pylint.sh`::

./tools/pylint.sh

When you think a warning is a false positive, add a comment before the specific line::
When you think a warning is a false positive, add a comment (see :doc:`pylint:user_guide/messages/message_control`)::

# pylint: disable=unused-argument
def some_function(*args, **kwargs)
def some_function(
something: SomeModel, # pylint: disable=unused-argument
*args,
**kwargs) -> None:
# pylint: disable=too-many-branches

.. Note::

Expand Down
1 change: 1 addition & 0 deletions docs/src/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"dateutil": ("https://dateutil.readthedocs.io/en/stable/", None),
"geopy": ("https://geopy.readthedocs.io/en/stable/", None),
"lxml": ("https://lxml.de/apidoc/", None),
"pylint": ("https://pylint.readthedocs.io/en/latest/", None),
"python": (
f"https://docs.python.org/{sys.version_info.major}.{sys.version_info.minor}/",
None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
from django.http import HttpRequest


# pylint: disable=too-few-public-methods
class JsonDebugToolbarMiddleware:
# pylint: disable=too-few-public-methods
"""
The Django Debug Toolbar usually only works for views that return HTML.
This middleware wraps any JSON response in HTML if the request
Expand Down
8 changes: 4 additions & 4 deletions integreat_cms/api/v3/chat/user_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,10 @@ def send_message(

@csrf_exempt
@json_response
# pylint: disable=unused-argument
def is_chat_enabled_for_user(
request: HttpRequest, region_slug: str, device_id: str
request: HttpRequest,
region_slug: str, # pylint: disable=unused-argument
device_id: str,
) -> JsonResponse:
"""
Function to check if the chat feature is enabled for the given region and the given user.
Expand All @@ -173,10 +174,9 @@ def is_chat_enabled_for_user(

@csrf_exempt
@json_response
# pylint: disable=unused-argument
def chat(
request: HttpRequest,
region_slug: str,
region_slug: str, # pylint: disable=unused-argument
language_slug: str,
device_id: str,
attachment_id: str = "",
Expand Down
6 changes: 4 additions & 2 deletions integreat_cms/api/v3/chat/utils/chat_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def automatic_answer(message: str, region: Region, language_slug: str) -> str |
f"https://{settings.INTEGREAT_CHAT_BACK_END_DOMAIN}/chatanswers/extract_answer/"
)
body = {"message": message, "language": language_slug, "region": region.slug}
r = requests.post(url, json=body, timeout=120)
r = requests.post(url, json=body, timeout=settings.INTEGREAT_CHAT_BACK_END_TIMEOUT)
return format_message(r.json())


Expand All @@ -58,7 +58,9 @@ def automatic_translation(
"source_language": source_language_slug,
"target_language": target_language_slug,
}
response = requests.post(url, json=body, timeout=120).json()
response = requests.post(
url, json=body, timeout=settings.INTEGREAT_CHAT_BACK_END_TIMEOUT
).json()
if "status" in response and response["status"] == "success":
return response["translation"]
raise ValueError("Did not receive success response for translation request.")
Expand Down
15 changes: 8 additions & 7 deletions integreat_cms/api/v3/chat/utils/zammad_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
AUTO_ANSWER_STRING = "automatically generated message"


# pylint: disable=unused-argument
def _raise_or_return_json(self: Any, response: HttpResponse) -> dict:
def _raise_or_return_json(
self: Any, response: HttpResponse # pylint: disable=unused-argument
) -> dict:
"""
Raise HTTPError before converting response to json
Expand All @@ -37,8 +38,8 @@ def _raise_or_return_json(self: Any, response: HttpResponse) -> dict:
return json_value


# pylint: disable=too-many-instance-attributes
class ZammadChatAPI:
# pylint: disable=too-many-instance-attributes
"""
Class providing an API for Zammad used in the context of user chats.
Expand Down Expand Up @@ -109,8 +110,8 @@ def _parse_response(self, response: dict | list[dict]) -> dict | list[dict]:

return {key: response[key] for key in keys_to_keep if key in response}

# pylint: disable=method-hidden
def create_ticket(self, device_id: str, language_slug: str) -> dict:
# pylint: disable=method-hidden
"""
Create a new ticket (i.e. initialize a new chat conversation)
Expand Down Expand Up @@ -141,8 +142,8 @@ def _transform_attachment(
)[0].random_hash,
}

# pylint: disable=method-hidden
def get_messages(self, chat: UserChat) -> dict[str, dict | list[dict]]:
# pylint: disable=method-hidden
"""
Get all non-internal messages for a given ticket
Expand All @@ -164,14 +165,14 @@ def get_messages(self, chat: UserChat) -> dict[str, dict | list[dict]]:

return {"messages": response}

# pylint: disable=method-hidden
def send_message(
self,
chat_id: int,
message: str,
internal: bool = False,
automatic_message: bool = False,
) -> dict:
# pylint: disable=method-hidden
"""
Post a new message to the given ticket
Expand All @@ -198,8 +199,8 @@ def send_message(
self._attempt_call(self.client.ticket_article.create, params=params)
)

# pylint: disable=method-hidden
def get_attachment(self, attachment_map: AttachmentMap) -> bytes | dict:
# pylint: disable=method-hidden
"""
Get the (binary) attachment file from Zammad.
Expand Down
7 changes: 5 additions & 2 deletions integreat_cms/api/v3/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,11 @@ def transform_event_recurrences(


@json_response
# pylint: disable=unused-argument
def events(request: HttpRequest, region_slug: str, language_slug: str) -> JsonResponse:
def events(
request: HttpRequest,
region_slug: str, # pylint: disable=unused-argument
language_slug: str,
) -> JsonResponse:
"""
List all events of the region and transform result into JSON
Expand Down
3 changes: 1 addition & 2 deletions integreat_cms/api/v3/feedback/event_list_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@

@feedback_handler
@json_response
# pylint: disable=unused-argument
def event_list_feedback(
data: dict,
data: dict, # pylint: disable=unused-argument
region: Region,
language: Language,
comment: str,
Expand Down
3 changes: 1 addition & 2 deletions integreat_cms/api/v3/feedback/imprint_page_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ def imprint_page_feedback(
)


# pylint: disable=unused-argument
def imprint_page_feedback_internal(
data: dict,
data: dict, # pylint: disable=unused-argument
region: Region,
language: Language,
comment: str,
Expand Down
3 changes: 1 addition & 2 deletions integreat_cms/api/v3/feedback/map_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@

@feedback_handler
@json_response
# pylint: disable=unused-argument
def map_feedback(
data: dict,
data: dict, # pylint: disable=unused-argument
region: Region,
language: Language,
comment: str,
Expand Down
3 changes: 1 addition & 2 deletions integreat_cms/api/v3/feedback/offer_list_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@

@feedback_handler
@json_response
# pylint: disable=unused-argument
def offer_list_feedback(
data: dict,
data: dict, # pylint: disable=unused-argument
region: Region,
language: Language,
comment: str,
Expand Down
3 changes: 1 addition & 2 deletions integreat_cms/api/v3/feedback/region_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@

@feedback_handler
@json_response
# pylint: disable=unused-argument
def region_feedback(
data: dict,
data: dict, # pylint: disable=unused-argument
region: Region,
language: Language,
comment: str,
Expand Down
7 changes: 5 additions & 2 deletions integreat_cms/api/v3/imprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ def transform_imprint(imprint_translation: ImprintPageTranslation) -> dict[str,


@json_response
# pylint: disable=unused-argument
def imprint(request: HttpRequest, region_slug: str, language_slug: str) -> JsonResponse:
def imprint(
request: HttpRequest,
region_slug: str, # pylint: disable=unused-argument
language_slug: str,
) -> JsonResponse:
"""
Get imprint for language and return JSON object to client. If no imprint translation
is available in the selected language, try to return the translation in the region
Expand Down
5 changes: 3 additions & 2 deletions integreat_cms/api/v3/languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ def transform_language(language: Language) -> dict[str, Any]:


@json_response
# pylint: disable=unused-argument
def languages(request: HttpRequest, region_slug: str) -> JsonResponse:
def languages(
request: HttpRequest, region_slug: str # pylint: disable=unused-argument
) -> JsonResponse:
"""
Function to add all languages related to a region to a JSON.
Expand Down
5 changes: 3 additions & 2 deletions integreat_cms/api/v3/location_categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ def transform_location_category(


@json_response
# pylint: disable=unused-argument
def location_categories(
request: HttpRequest, region_slug: str, language_slug: str
request: HttpRequest,
region_slug: str, # pylint: disable=unused-argument
language_slug: str,
) -> JsonResponse:
"""
Function to return all POI categories as JSON.
Expand Down
5 changes: 3 additions & 2 deletions integreat_cms/api/v3/locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ def transform_poi_translation(poi_translation: POITranslation) -> dict[str, Any]


@json_response
# pylint: disable=unused-argument
def locations(
request: HttpRequest, region_slug: str, language_slug: str
request: HttpRequest,
region_slug: str, # pylint: disable=unused-argument
language_slug: str,
) -> JsonResponse:
"""
List all POIs of the region and transform result into JSON
Expand Down
5 changes: 3 additions & 2 deletions integreat_cms/api/v3/offers.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ def transform_offer(offer: OfferTemplate, region: Region) -> dict[str, Any]:


@json_response
# pylint: disable=unused-argument
def offers(
request: HttpRequest, region_slug: str, language_slug: str | None = None
request: HttpRequest,
region_slug: str, # pylint: disable=unused-argument
language_slug: str | None = None, # pylint: disable=unused-argument
) -> JsonResponse:
"""
Function to iterate through all offers related to a region and adds them to a JSON.
Expand Down
22 changes: 14 additions & 8 deletions integreat_cms/api/v3/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,11 @@ def transform_page(page_translation: PageTranslation) -> dict[str, Any]:

@matomo_tracking
@json_response
# pylint: disable=unused-argument
def pages(request: HttpRequest, region_slug: str, language_slug: str) -> JsonResponse:
def pages(
request: HttpRequest,
region_slug: str, # pylint: disable=unused-argument
language_slug: str,
) -> JsonResponse:
"""
Function to iterate through all non-archived pages of a region and return them as JSON.
Expand Down Expand Up @@ -205,9 +208,10 @@ def get_single_page(request: HttpRequest, language_slug: str) -> Page:


@json_response
# pylint: disable=unused-argument
def single_page(
request: HttpRequest, region_slug: str, language_slug: str
request: HttpRequest,
region_slug: str, # pylint: disable=unused-argument
language_slug: str,
) -> JsonResponse:
"""
View function returning the desired page as a JSON or a 404 if the
Expand Down Expand Up @@ -277,8 +281,11 @@ def children(


@json_response
# pylint: disable=unused-argument
def parents(request: HttpRequest, region_slug: str, language_slug: str) -> JsonResponse:
def parents(
request: HttpRequest,
region_slug: str, # pylint: disable=unused-argument
language_slug: str,
) -> JsonResponse:
"""
Retrieves all ancestors (parent and all nodes up to the root node) of a page.
If any ancestor is archived, an 404 is raised.
Expand Down Expand Up @@ -326,10 +333,9 @@ def get_public_ancestor_translations(

@csrf_exempt
@json_response
# pylint: disable=unused-argument
def push_page_translation_content(
request: HttpRequest,
region_slug: str,
region_slug: str, # pylint: disable=unused-argument
language_slug: str,
) -> JsonResponse:
"""
Expand Down
5 changes: 3 additions & 2 deletions integreat_cms/api/v3/pdf_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@

@json_response
@never_cache
# pylint: disable=unused-argument
def pdf_export(
request: HttpRequest, region_slug: str, language_slug: str
request: HttpRequest,
region_slug: str, # pylint: disable=unused-argument
language_slug: str,
) -> HttpResponseRedirect:
"""
View function that either returns the requested page specified by the
Expand Down
5 changes: 3 additions & 2 deletions integreat_cms/api/v3/regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ def regions(_: HttpRequest) -> JsonResponse:


@json_response
# pylint: disable=unused-argument
def region_by_slug(request: HttpRequest, region_slug: str) -> JsonResponse:
def region_by_slug(
request: HttpRequest, region_slug: str # pylint: disable=unused-argument
) -> JsonResponse:
"""
Retrieve a single region and transform result into JSON
Expand Down
Loading

0 comments on commit 4b851bf

Please sign in to comment.