comparison user_photos/forms.py @ 696:b2a8fde3173a

Got the image resizing and uploading working. It needs a lot of work though. This commit is just to capture something that works.
author Brian Neal <bgneal@gmail.com>
date Sun, 08 Sep 2013 19:06:54 -0500
parents 2d35e5f97a99
children 67f8d49a9377
comparison
equal deleted inserted replaced
695:2d35e5f97a99 696:b2a8fde3173a
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
4 from user_photos.models import Photo
5 from user_photos.images import process_file
3 6
4 7
5 class UploadForm(forms.Form): 8 class UploadForm(forms.Form):
6 image_file = forms.ImageField() 9 image_file = forms.ImageField()
10
11 def __init__(self, *args, **kwargs):
12 self.user = kwargs.pop('user')
13 super(UploadForm, self).__init__(*args, **kwargs)
14
15 def save(self):
16 """Processes the image and creates a new Photo object, which is saved to
17 the database. The new Photo instance is returned.
18
19 This function should only be called if is_valid() returns True.
20
21 """
22 url, thumb_url = process_file(self.cleaned_data['image_file'], self.user)
23 photo = Photo(user=self.user, url=url, thumb_url=thumb_url)
24 photo.save()
25 return photo