Mercurial > public > sg101
diff user_photos/forms.py @ 1195:7fc6c42b2f5b
Adding a local user photo upload option.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 07 May 2023 16:22:13 -0500 |
parents | f5aa74dcdd7a |
children |
line wrap: on
line diff
--- a/user_photos/forms.py Sun Mar 19 10:36:38 2023 -0500 +++ b/user_photos/forms.py Sun May 07 16:22:13 2023 -0500 @@ -1,5 +1,4 @@ """Forms for the user_photos application.""" -import datetime import hashlib import os.path import urlparse @@ -9,8 +8,7 @@ from core.download import download_file from core.functions import remove_file, TemporaryFile -from core.images.upload import upload -from core.s3 import S3Bucket +from core.images.upload import process_upload from core.services import get_redis_connection from user_photos.models import Photo @@ -70,12 +68,6 @@ except Photo.DoesNotExist: pass - # This must not be a duplicate, proceed with upload to S3 - bucket = S3Bucket(access_key=settings.USER_PHOTOS_ACCESS_KEY, - secret_key=settings.USER_PHOTOS_SECRET_KEY, - base_url=settings.USER_PHOTOS_BASE_URL, - bucket_name=settings.USER_PHOTOS_BUCKET) - # Trying to use PIL (or Pillow) on a Django UploadedFile is often # problematic because the file is often an in-memory file if it is under # a certain size. This complicates matters and many of the operations we try @@ -91,14 +83,7 @@ t.file.write(chunk) t.file.close() - now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') - metadata = {'user': self.user.username, 'date': now} - - url, thumb_url = upload(filename=t.filename, - bucket=bucket, - metadata=metadata, - new_size=settings.USER_PHOTOS_MAX_SIZE, - thumb_size=settings.USER_PHOTOS_THUMB_SIZE) + url, thumb_url = process_upload(self.user, t.filename) photo = Photo(user=self.user, url=url, thumb_url=thumb_url, signature=signature) @@ -151,19 +136,6 @@ # Try to download the file with remove_file(download_file(url)) as path: - - # Upload it to our S3 bucket - bucket = S3Bucket(access_key=settings.USER_PHOTOS_ACCESS_KEY, - secret_key=settings.USER_PHOTOS_SECRET_KEY, - base_url=settings.HOT_LINK_PHOTOS_BASE_URL, - bucket_name=settings.HOT_LINK_PHOTOS_BUCKET) - - now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') - metadata = {'user': self.user.username, 'date': now} - - url, _ = upload(filename=path, - bucket=bucket, - metadata=metadata, - new_size=settings.USER_PHOTOS_MAX_SIZE) + url, _ = process_upload(self.user, path) return url