From 733d204467dabb633eb1fd0610ffc3fa5a455391 Mon Sep 17 00:00:00 2001 From: David Venhoff Date: Wed, 26 Oct 2022 16:52:03 +0200 Subject: [PATCH] Fix fallback feedback for events and pois Previously, an error was returned when the feedback was about a fallback translated object. Now, the default language gets used if required. The actual language of the feedback should not get lost, though. Co-authored-by: Timo Ludwig --- CHANGELOG.md | 2 ++ .../api/v3/feedback/event_feedback.py | 20 +++++++++++++++---- integreat_cms/api/v3/feedback/poi_feedback.py | 18 ++++++++++++++--- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f9e67123b..6bec7314bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ UNRELEASED ---------- +* [ [#1718](https://github.com/digitalfabrik/integreat-cms/issues/1718) ] Enable submitting feedback about fallback translations of events and pois + 2022.10.2 --------- diff --git a/integreat_cms/api/v3/feedback/event_feedback.py b/integreat_cms/api/v3/feedback/event_feedback.py index e577267198..c03e1dc73e 100644 --- a/integreat_cms/api/v3/feedback/event_feedback.py +++ b/integreat_cms/api/v3/feedback/event_feedback.py @@ -81,10 +81,22 @@ def event_feedback_internal(data, region, language, comment, rating, is_technica events, ) return JsonResponse({"error": "Internal Server Error"}, status=500) - if len(events) == 0: - raise Http404("No matching event found for slug.") - event = events[0] - event_translation = event.get_translation(language.slug) + + event = None + if len(events) == 1: + event = events[0] + elif region.fallback_translations_enabled: + event = region.events.filter( + translations__slug=data.get("slug"), + translations__language=region.default_language, + ).first() + + if not event: + raise Http404("No matching location found for slug.") + + event_translation = event.get_translation(language.slug) or event.get_translation( + region.default_language.slug + ) EventFeedback.objects.create( event_translation=event_translation, diff --git a/integreat_cms/api/v3/feedback/poi_feedback.py b/integreat_cms/api/v3/feedback/poi_feedback.py index 5cb8f576d3..36c12cff06 100644 --- a/integreat_cms/api/v3/feedback/poi_feedback.py +++ b/integreat_cms/api/v3/feedback/poi_feedback.py @@ -51,10 +51,22 @@ def poi_feedback(data, region, language, comment, rating, is_technical): pois, ) return JsonResponse({"error": "Internal Server Error"}, status=500) - if len(pois) == 0: + + poi = None + if len(pois) == 1: + poi = pois[0] + elif region.fallback_translations_enabled: + poi = region.pois.filter( + translations__slug=data.get("slug"), + translations__language=region.default_language, + ).first() + + if not poi: raise Http404("No matching location found for slug.") - poi = pois[0] - poi_translation = poi.get_translation(language.slug) + + poi_translation = poi.get_translation(language.slug) or poi.get_translation( + region.default_language.slug + ) POIFeedback.objects.create( poi_translation=poi_translation,