Browse Source

Make sure all media files are with full URLS

master
Joshua Rubingh 4 months ago
parent
commit
14a9bdaf2f
  1. 5
      VRE/apps/researcher/views.py

5
VRE/apps/researcher/views.py

@ -36,13 +36,14 @@ class Researchers(viewsets.ModelViewSet): @@ -36,13 +36,14 @@ class Researchers(viewsets.ModelViewSet):
if not hasattr(request.user,'researcher'):
raise PermissionDenied(_('Illegal user'))
return Response(ResearcherDetailSerializer(request.user.researcher).data)
# Make the avatar images contain full urls: https://stackoverflow.com/a/49204239
return Response(ResearcherDetailSerializer(request.user.researcher, context={"request":request}).data)
@swagger_auto_schema(request_body=ResearcherSerializer(many=False), responses={200: ResearcherDetailSerializer(many=False)})
def update(self, request, *args, **kwargs):
# Set a 'fake' pk value so we can use the normal serializer update
request.parser_context['kwargs']['pk'] = request.user.researcher.id
if request.data.get('avatar') and (request.data['avatar'].startswith('/media/') or request.data['avatar'].startswith('http://') or request.data['avatar'].startswith('https://')):
if request.data.get('avatar') and (request.data['avatar'].startswith('http://') or request.data['avatar'].startswith('https://')):
# Do not change the existing avatar image.
del(request.data['avatar'])

Loading…
Cancel
Save