Skip to content

Commit

Permalink
Merge pull request #1811 from digitalfabrik/bugfix/fallback-feedback
Browse files Browse the repository at this point in the history
Fix fallback feedback for events and pois
  • Loading branch information
david-venhoff authored Oct 29, 2022
2 parents c87c51f + 733d204 commit d38f5b0
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 d38f5b0

Please sign in to comment.