-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
updated the serializer to yield a full glyph path #784
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,33 @@ | ||
from rest_framework import serializers | ||
|
||
from mezzanine.conf import settings | ||
from networkapi.news.models import News | ||
|
||
|
||
class NewsSerializer(serializers.ModelSerializer): | ||
|
||
glyph = serializers.SerializerMethodField() | ||
|
||
def get_glyph(self, instance): | ||
print (settings.USE_S3) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. leftover print |
||
|
||
# Remote hosted? Return the remote URL | ||
if settings.USE_S3: | ||
return "{host}{glyph}".format( | ||
host=settings.MEDIA_URL, | ||
glyph=instance.glyph | ||
) | ||
|
||
# Stored on the local filesystem: return as an absolute URL | ||
request = self.context['request'] | ||
|
||
return "{protocol}://{root}{url}{glyph}".format( | ||
protocol='https' if request.is_secure() else 'http', | ||
root=request.META['HTTP_HOST'], | ||
url=settings.MEDIA_URL, | ||
glyph=str(instance.glyph).replace(' ','%20') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: might wanna try https://docs.python.org/3.6/library/urllib.parse.html#urllib.parse.quote instead |
||
) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think it's 1 blank line for nested classes. But personally don't mind as long as flake8 doesn't complain |
||
|
||
""" | ||
Serializes a News object | ||
""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flake8 might complain about this