Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Pass the request to the serializer

Roland Geider3baf23b62b1c
diff --git a/wger/trophies/api/serializers.py b/wger/trophies/api/serializers.py
index f94e62ddf..bab681a46 100644
--- a/wger/trophies/api/serializers.py
+++ b/wger/trophies/api/serializers.py
@@ -60,10 +60,9 @@ class TrophySerializer(serializers.ModelSerializer):
def get_image(self, obj: Trophy):
"""Build absolute URL to trophy image, if possible."""
- static_url = static(obj.image_rel_path)
request = self.context.get('request')
if request is not None:
- return request.build_absolute_uri(static_url)
+ return request.build_absolute_uri(static(obj.image_rel_path))
# no host available
logger.info('Cannot build absolute URL for trophy image without request context')
diff --git a/wger/trophies/api/views.py b/wger/trophies/api/views.py
index d46e7834e..c3e9723aa 100644
--- a/wger/trophies/api/views.py
+++ b/wger/trophies/api/views.py
@@ -126,7 +126,13 @@ class TrophyViewSet(viewsets.ReadOnlyModelViewSet):
include_hidden=include_hidden,
)
- serializer = TrophyProgressSerializer(progress_data, many=True)
+ serializer = TrophyProgressSerializer(
+ progress_data,
+ many=True,
+
+ # Important: provide request in context for image URL building
+ context={'request': request}
+ )
return Response(serializer.data)