Mercurial > public > sg101
comparison user_photos/views.py @ 695:2d35e5f97a99
In process work for #50. Started a user_photos application.
Initial commit with model, form, and view. The view doesn't save the photo yet.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 07 Sep 2013 20:50:46 -0500 |
parents | |
children | b2a8fde3173a |
comparison
equal
deleted
inserted
replaced
694:d84aaf239182 | 695:2d35e5f97a99 |
---|---|
1 """Views for the user_photos application.""" | |
2 from django.conf import settings | |
3 from django.contrib.auth.decorators import login_required | |
4 from django.shortcuts import render | |
5 | |
6 from user_photos.forms import UploadForm | |
7 | |
8 | |
9 @login_required | |
10 def upload(request): | |
11 """This view function receives an uploaded image file from a user. | |
12 The photo will be resized if necessary and a thumbnail image will be | |
13 created. The image and thumbnail will then be uploaded to the Amazon | |
14 S3 service for storage. | |
15 | |
16 TODO: rate limiting | |
17 pass off the processing to a celery task | |
18 ajax version of this view | |
19 | |
20 """ | |
21 form = None | |
22 uploads_enabled = settings.USER_PHOTO_ENABLED | |
23 | |
24 if uploads_enabled: | |
25 if request.method == 'POST': | |
26 form = UploadForm(request.POST, request.FILES) | |
27 if form.is_valid(): | |
28 #TODO | |
29 print "**************", request.FILES['image_file'] | |
30 pass | |
31 else: | |
32 form = UploadForm() | |
33 | |
34 return render(request, 'user_photos/upload_form.html', { | |
35 'enabled': uploads_enabled, | |
36 'form': form, | |
37 }, | |
38 status=200 if uploads_enabled else 503) |