comparison 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
comparison
equal deleted inserted replaced
696:b2a8fde3173a 697:67f8d49a9377
1 """Forms for the user_photos application.""" 1 """Forms for the user_photos application."""
2 from django import forms 2 from django import forms
3 from django.conf import settings
3 4
4 from user_photos.models import Photo 5 from user_photos.models import Photo
5 from user_photos.images import process_file 6 from user_photos.images import process_file
7 from user_photos.s3 import S3Bucket
6 8
7 9
8 class UploadForm(forms.Form): 10 class UploadForm(forms.Form):
9 image_file = forms.ImageField() 11 image_file = forms.ImageField()
10 12
17 the database. The new Photo instance is returned. 19 the database. The new Photo instance is returned.
18 20
19 This function should only be called if is_valid() returns True. 21 This function should only be called if is_valid() returns True.
20 22
21 """ 23 """
22 url, thumb_url = process_file(self.cleaned_data['image_file'], self.user) 24 bucket = S3Bucket(settings.USER_PHOTOS_ACCESS_KEY,
25 settings.USER_PHOTOS_SECRET_KEY,
26 settings.USER_PHOTOS_BUCKET)
27 url, thumb_url = process_file(self.cleaned_data['image_file'],
28 self.user,
29 bucket)
23 photo = Photo(user=self.user, url=url, thumb_url=thumb_url) 30 photo = Photo(user=self.user, url=url, thumb_url=thumb_url)
24 photo.save() 31 photo.save()
25 return photo 32 return photo