diff user_photos/forms.py @ 697:67f8d49a9377

Cleaned up the code a bit. Separated the S3 stuff out into its own class. This class maybe should be in core. Still want to do some kind of context manager around the temporary file we are creating to ensure it gets deleted.
author Brian Neal <bgneal@gmail.com>
date Sun, 08 Sep 2013 21:02:58 -0500
parents b2a8fde3173a
children e888d627928f
line wrap: on
line diff
--- a/user_photos/forms.py	Sun Sep 08 19:06:54 2013 -0500
+++ b/user_photos/forms.py	Sun Sep 08 21:02:58 2013 -0500
@@ -1,8 +1,10 @@
 """Forms for the user_photos application."""
 from django import forms
+from django.conf import settings
 
 from user_photos.models import Photo
 from user_photos.images import process_file
+from user_photos.s3 import S3Bucket
 
 
 class UploadForm(forms.Form):
@@ -19,7 +21,12 @@
         This function should only be called if is_valid() returns True.
 
         """
-        url, thumb_url = process_file(self.cleaned_data['image_file'], self.user)
+        bucket = S3Bucket(settings.USER_PHOTOS_ACCESS_KEY,
+                          settings.USER_PHOTOS_SECRET_KEY,
+                          settings.USER_PHOTOS_BUCKET)
+        url, thumb_url = process_file(self.cleaned_data['image_file'],
+                                      self.user,
+                                      bucket)
         photo = Photo(user=self.user, url=url, thumb_url=thumb_url)
         photo.save()
         return photo