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 ...@@ -8,6 +8,7 @@ from django.utils.html import strip_tags
from rest_framework import serializers from rest_framework import serializers
from events.models import Event, Registration from events.models import Event, Registration
from thaliawebsite.settings import settings
class CalenderJSSerializer(serializers.ModelSerializer): class CalenderJSSerializer(serializers.ModelSerializer):
...@@ -182,13 +183,8 @@ class EventRegistrationSerializer(serializers.ModelSerializer): ...@@ -182,13 +183,8 @@ class EventRegistrationSerializer(serializers.ModelSerializer):
def _photo(self, instance): def _photo(self, instance):
if instance.member and instance.member.photo: if instance.member and instance.member.photo:
f = instance.member.photo.file return self.context['request'].build_absolute_uri(
type = mimetypes.guess_type(f.name)[0] '%s%s' % (settings.MEDIA_URL, instance.member.photo))
photo = ''.join(['data:{};base64,'.format(type),
b64encode(f.read()).decode()])
else: else:
filename = find_static_file('members/images/default-avatar.jpg') return self.context['request'].build_absolute_uri(
with open(filename, 'rb') as f: 'members/images/default-avatar.jpg')
photo = ''.join(['data:image/jpeg;base64,',
b64encode(f.read()).decode()])
return photo
...@@ -47,7 +47,8 @@ class EventViewset(viewsets.ReadOnlyModelViewSet): ...@@ -47,7 +47,8 @@ class EventViewset(viewsets.ReadOnlyModelViewSet):
event = Event.objects.get(pk=pk) event = Event.objects.get(pk=pk)
queryset = Registration.objects.filter( queryset = Registration.objects.filter(
event=pk, date_cancelled=None)[:event.max_participants] 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) 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