Mercurial > public > sg101
annotate 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 |
rev | line source |
---|---|
bgneal@695 | 1 """Views for the user_photos application.""" |
bgneal@695 | 2 from django.conf import settings |
bgneal@695 | 3 from django.contrib.auth.decorators import login_required |
bgneal@695 | 4 from django.shortcuts import render |
bgneal@695 | 5 |
bgneal@695 | 6 from user_photos.forms import UploadForm |
bgneal@695 | 7 |
bgneal@695 | 8 |
bgneal@695 | 9 @login_required |
bgneal@695 | 10 def upload(request): |
bgneal@695 | 11 """This view function receives an uploaded image file from a user. |
bgneal@695 | 12 The photo will be resized if necessary and a thumbnail image will be |
bgneal@695 | 13 created. The image and thumbnail will then be uploaded to the Amazon |
bgneal@695 | 14 S3 service for storage. |
bgneal@695 | 15 |
bgneal@695 | 16 TODO: rate limiting |
bgneal@695 | 17 pass off the processing to a celery task |
bgneal@695 | 18 ajax version of this view |
bgneal@695 | 19 |
bgneal@695 | 20 """ |
bgneal@695 | 21 form = None |
bgneal@695 | 22 uploads_enabled = settings.USER_PHOTO_ENABLED |
bgneal@695 | 23 |
bgneal@695 | 24 if uploads_enabled: |
bgneal@695 | 25 if request.method == 'POST': |
bgneal@695 | 26 form = UploadForm(request.POST, request.FILES) |
bgneal@695 | 27 if form.is_valid(): |
bgneal@695 | 28 #TODO |
bgneal@695 | 29 print "**************", request.FILES['image_file'] |
bgneal@695 | 30 pass |
bgneal@695 | 31 else: |
bgneal@695 | 32 form = UploadForm() |
bgneal@695 | 33 |
bgneal@695 | 34 return render(request, 'user_photos/upload_form.html', { |
bgneal@695 | 35 'enabled': uploads_enabled, |
bgneal@695 | 36 'form': form, |
bgneal@695 | 37 }, |
bgneal@695 | 38 status=200 if uploads_enabled else 503) |