Skip to content

Commit

Permalink
Fix fallback feedback for events and pois
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
david-venhoff and timobrembeck committed Oct 28, 2022
1 parent c87c51f commit 733d204
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
---------
Expand Down
20 changes: 16 additions & 4 deletions integreat_cms/api/v3/feedback/event_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 15 additions & 3 deletions integreat_cms/api/v3/feedback/poi_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 733d204

Please sign in to comment.