Mercurial > public > sg101
annotate user_photos/s3.py @ 943:cf9918328c64
Haystack tweaks for Django 1.7.7.
I had to upgrade to Haystack 2.3.1 to get it to work with Django
1.7.7. I also had to update the Xapian backend. But I ran into
problems.
On my laptop anyway (Ubuntu 14.0.4), xapian gets mad when search terms
are greater than 245 chars (or something) when indexing. So I created
a custom field that would simply omit terms greater than 64 chars and
used this field everywhere I previously used a CharField.
Secondly, the custom search form was broken now. Something changed in
the Xapian backend and exact searches stopped working. Fortunately the
auto_query (which I was using originally and broke during an upgrade)
started working again. So I cut the search form back over to doing an
auto_query. I kept the form the same (3 fields) because I didn't want
to change the form and I think it's better that way.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 13 May 2015 20:25:07 -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 |