annotate user_photos/views.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 809d27b385f2
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@696 4 from django.shortcuts import render, redirect
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@696 22 uploads_enabled = settings.USER_PHOTOS_ENABLED
bgneal@695 23
bgneal@695 24 if uploads_enabled:
bgneal@695 25 if request.method == 'POST':
bgneal@696 26 form = UploadForm(request.POST, request.FILES, user=request.user)
bgneal@695 27 if form.is_valid():
bgneal@696 28 photo = form.save()
bgneal@696 29 return redirect(photo)
bgneal@695 30 else:
bgneal@696 31 form = UploadForm(user=request.user)
bgneal@695 32
bgneal@695 33 return render(request, 'user_photos/upload_form.html', {
bgneal@695 34 'enabled': uploads_enabled,
bgneal@695 35 'form': form,
bgneal@695 36 },
bgneal@695 37 status=200 if uploads_enabled else 503)