Mercurial > public > sg101
diff 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 |
line wrap: on
line diff
--- a/user_photos/forms.py Sat Sep 07 20:50:46 2013 -0500 +++ b/user_photos/forms.py Sun Sep 08 19:06:54 2013 -0500 @@ -1,6 +1,25 @@ """Forms for the user_photos application.""" from django import forms +from user_photos.models import Photo +from user_photos.images import process_file + class UploadForm(forms.Form): image_file = forms.ImageField() + + def __init__(self, *args, **kwargs): + self.user = kwargs.pop('user') + super(UploadForm, self).__init__(*args, **kwargs) + + def save(self): + """Processes the image and creates a new Photo object, which is saved to + the database. The new Photo instance is returned. + + This function should only be called if is_valid() returns True. + + """ + url, thumb_url = process_file(self.cleaned_data['image_file'], self.user) + photo = Photo(user=self.user, url=url, thumb_url=thumb_url) + photo.save() + return photo