From dd85e3c46f995187b772075d34d5b0add8d32c99 Mon Sep 17 00:00:00 2001 From: Simon Baechler Date: Thu, 15 Jan 2015 15:55:57 +0100 Subject: [PATCH] add more s3 info and feincms_thumbnail override --- fbox/utils/feincms_sorl_thumbnailer.py | 26 ++++++++++++++++++++++++++ fbox/utils/s3utils.py | 13 +++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 fbox/utils/feincms_sorl_thumbnailer.py diff --git a/fbox/utils/feincms_sorl_thumbnailer.py b/fbox/utils/feincms_sorl_thumbnailer.py new file mode 100644 index 0000000..05acf7d --- /dev/null +++ b/fbox/utils/feincms_sorl_thumbnailer.py @@ -0,0 +1,26 @@ +# coding: utf-8 +""" +Thumbnailer class for FeinCMS. +Allows using sorl thumbnail as default thumbnailer. +Use this if you have mediafiles stored on S3. + +Add this line to your settings: + + FEINCMS_MEDIALIBRARY_THUMBNAIL = 'feincms_sorl_thumbnailer.thumbnailer' + +""" +from __future__ import unicode_literals +from sorl.thumbnail import get_thumbnail + + +def thumbnailer(mediafile, dimensions='100x100', quality=65, **kwargs): + """ + Function called by FeinCMS medialibrary.thumbnail.admin_thumbnail + :param mediafile: - the mediafile object + :param kwargs: - options passed to the thumbnailer + :return: - URL of the thumbnail + """ + if mediafile.type == 'image': + im = get_thumbnail(mediafile.file, dimensions, quality=quality) + return im.url + return '' diff --git a/fbox/utils/s3utils.py b/fbox/utils/s3utils.py index ee7ff81..2bf582f 100644 --- a/fbox/utils/s3utils.py +++ b/fbox/utils/s3utils.py @@ -1,6 +1,19 @@ """ Custom S3 storage backends to store files in subfolders. Use this backend with the boto storage app. + +Make sure you use an alternative thumbnailer class for FeinCMS, such as +feincms_sorl_thumbnailer. + +Use these settings for S3: + +AWS_ACCESS_KEY_ID = env('AWS_ACCESS_KEY_ID') +AWS_SECRET_ACCESS_KEY = env('AWS_SECRET_ACCESS_KEY') +AWS_STORAGE_BUCKET_NAME = 'iraqiodyssee' +AWS_LOCATION = '/media/' +AWS_QUERYSTRING_EXPIRE = 60*60*48 +AWS_S3_FILE_OVERWRITE = False + """ from storages.backends.s3boto import S3BotoStorage