Skip to content
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

Merged
merged 3 commits into from
Sep 25, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion network-api/app/networkapi/news/serializers.py
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


Copy link
Contributor

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

class NewsSerializer(serializers.ModelSerializer):

glyph = serializers.SerializerMethodField()

def get_glyph(self, instance):
print (settings.USE_S3)
Copy link
Contributor

Choose a reason for hiding this comment

The 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')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

)

Copy link
Contributor

Choose a reason for hiding this comment

The 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
"""
Expand Down