Verified Commit 96f0c711 authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Use direct photo url instead of base64 since no saving is necessary

parent 65fb2efd
......@@ -8,6 +8,7 @@ from django.utils.html import strip_tags
from rest_framework import serializers
from events.models import Event, Registration
from thaliawebsite.settings import settings
class CalenderJSSerializer(serializers.ModelSerializer):
......@@ -182,13 +183,8 @@ class EventRegistrationSerializer(serializers.ModelSerializer):
def _photo(self, instance):
if instance.member and instance.member.photo:
f = instance.member.photo.file
type = mimetypes.guess_type(f.name)[0]
photo = ''.join(['data:{};base64,'.format(type),
b64encode(f.read()).decode()])
return self.context['request'].build_absolute_uri(
'%s%s' % (settings.MEDIA_URL, instance.member.photo))
else:
filename = find_static_file('members/images/default-avatar.jpg')
with open(filename, 'rb') as f:
photo = ''.join(['data:image/jpeg;base64,',
b64encode(f.read()).decode()])
return photo
return self.context['request'].build_absolute_uri(
'members/images/default-avatar.jpg')
......@@ -47,7 +47,8 @@ class EventViewset(viewsets.ReadOnlyModelViewSet):
event = Event.objects.get(pk=pk)
queryset = Registration.objects.filter(
event=pk, date_cancelled=None)[:event.max_participants]
serializer = EventRegistrationSerializer(queryset, many=True)
serializer = EventRegistrationSerializer(queryset, many=True,
context={'request': request})
return Response(serializer.data)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment