Skip to content

Commit

Permalink
Merge pull request #1690 from kettenbach-it/develop
Browse files Browse the repository at this point in the history
Get image from S3-storage if configured
  • Loading branch information
vabene1111 authored Apr 4, 2022
2 parents bba81f6 + b6e5425 commit dfa5475
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cookbook/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
SupermarketCategory, SupermarketCategoryRelation, Sync, SyncLog, Unit,
UserFile, UserPreference, ViewLog)
from cookbook.templatetags.custom_tags import markdown
from recipes.settings import MEDIA_URL
from cookbook.helper.CustomStorageClass import CachedS3Boto3Storage
from recipes.settings import MEDIA_URL, AWS_S3_ENDPOINT_URL, AWS_ACCESS_KEY_ID


class ExtendedRecipeMixin(serializers.ModelSerializer):
Expand Down Expand Up @@ -54,7 +55,12 @@ def get_fields(self, *args, **kwargs):

def get_image(self, obj):
if obj.recipe_image:
return MEDIA_URL + obj.recipe_image
if AWS_ACCESS_KEY_ID and AWS_S3_ENDPOINT_URL:
storage = CachedS3Boto3Storage()
path = storage.url(obj.recipe_image)
else:
path = MEDIA_URL + obj.recipe_image
return path


class CustomDecimalField(serializers.Field):
Expand Down

0 comments on commit dfa5475

Please sign in to comment.