Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
thalia
concrexit
Commits
96f0c711
Verified
Commit
96f0c711
authored
May 27, 2017
by
Sébastiaan Versteeg
Browse files
Use direct photo url instead of base64 since no saving is necessary
parent
65fb2efd
Changes
2
Hide whitespace changes
Inline
Side-by-side
website/events/api/serializers.py
View file @
96f0c711
...
...
@@ -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'
)
website/events/api/viewsets.py
View file @
96f0c711
...
...
@@ -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
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment