Merge pull request #1690 from kettenbach-it/develop
Get image from S3-storage if configured
This commit is contained in:
commit
dfa5475ecb
@ -20,7 +20,8 @@ from cookbook.models import (Automation, BookmarkletImport, Comment, CookLog, Cu
|
|||||||
SupermarketCategory, SupermarketCategoryRelation, Sync, SyncLog, Unit,
|
SupermarketCategory, SupermarketCategoryRelation, Sync, SyncLog, Unit,
|
||||||
UserFile, UserPreference, ViewLog)
|
UserFile, UserPreference, ViewLog)
|
||||||
from cookbook.templatetags.custom_tags import markdown
|
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):
|
class ExtendedRecipeMixin(serializers.ModelSerializer):
|
||||||
@ -54,7 +55,12 @@ class ExtendedRecipeMixin(serializers.ModelSerializer):
|
|||||||
|
|
||||||
def get_image(self, obj):
|
def get_image(self, obj):
|
||||||
if obj.recipe_image:
|
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):
|
class CustomDecimalField(serializers.Field):
|
||||||
|
Loading…
Reference in New Issue
Block a user