Mercurial > public > sg101
annotate user_photos/s3.py @ 989:2908859c2fe4
Smilies now use relative links.
This is for upcoming switch to SSL. Currently we do not need absolute URLs for
smilies. If this changes we can add it later.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 29 Oct 2015 20:54:34 -0500 |
parents | bf5340705d0c |
children |
rev | line source |
---|---|
bgneal@718 | 1 """Module for all S3 related operations for the user_photos application.""" |
bgneal@718 | 2 |
bgneal@718 | 3 import logging |
bgneal@718 | 4 |
bgneal@718 | 5 from django.conf import settings |
bgneal@718 | 6 |
bgneal@718 | 7 from core.s3 import S3Bucket |
bgneal@718 | 8 |
bgneal@718 | 9 |
bgneal@718 | 10 logger = logging.getLogger(__name__) |
bgneal@718 | 11 |
bgneal@718 | 12 |
bgneal@718 | 13 def delete_photos(qs): |
bgneal@718 | 14 """Delete the photos stored on S3 for the given Photo queryset. |
bgneal@718 | 15 |
bgneal@718 | 16 Returns the number of photos actually deleted. |
bgneal@718 | 17 |
bgneal@718 | 18 """ |
bgneal@718 | 19 |
bgneal@718 | 20 bucket = S3Bucket(settings.USER_PHOTOS_ACCESS_KEY, |
bgneal@718 | 21 settings.USER_PHOTOS_SECRET_KEY, |
bgneal@718 | 22 settings.USER_PHOTOS_BASE_URL, |
bgneal@718 | 23 settings.USER_PHOTOS_BUCKET) |
bgneal@718 | 24 |
bgneal@718 | 25 key_urls = [] |
bgneal@718 | 26 for photo in qs: |
bgneal@718 | 27 key_urls.append(photo.url) |
bgneal@718 | 28 key_urls.append(photo.thumb_url) |
bgneal@718 | 29 req_cnt = len(key_urls) |
bgneal@718 | 30 |
bgneal@718 | 31 logger.info("Requesting deletion of %d user photo(s) from S3", req_cnt) |
bgneal@718 | 32 |
bgneal@718 | 33 act_cnt = bucket.delete_keys(key_urls) |
bgneal@718 | 34 |
bgneal@718 | 35 if act_cnt == req_cnt: |
bgneal@718 | 36 logger.info("Deleted %d user photo(s) from S3", act_cnt) |
bgneal@718 | 37 else: |
bgneal@718 | 38 logger.warning("Deleted %d user photo(s) out of %d", act_cnt, req_cnt) |
bgneal@718 | 39 |
bgneal@718 | 40 return act_cnt |