bgneal@695: """Views for the user_photos application.""" bgneal@695: from django.conf import settings bgneal@695: from django.contrib.auth.decorators import login_required bgneal@695: from django.shortcuts import render bgneal@695: bgneal@695: from user_photos.forms import UploadForm bgneal@695: bgneal@695: bgneal@695: @login_required bgneal@695: def upload(request): bgneal@695: """This view function receives an uploaded image file from a user. bgneal@695: The photo will be resized if necessary and a thumbnail image will be bgneal@695: created. The image and thumbnail will then be uploaded to the Amazon bgneal@695: S3 service for storage. bgneal@695: bgneal@695: TODO: rate limiting bgneal@695: pass off the processing to a celery task bgneal@695: ajax version of this view bgneal@695: bgneal@695: """ bgneal@695: form = None bgneal@695: uploads_enabled = settings.USER_PHOTO_ENABLED bgneal@695: bgneal@695: if uploads_enabled: bgneal@695: if request.method == 'POST': bgneal@695: form = UploadForm(request.POST, request.FILES) bgneal@695: if form.is_valid(): bgneal@695: #TODO bgneal@695: print "**************", request.FILES['image_file'] bgneal@695: pass bgneal@695: else: bgneal@695: form = UploadForm() bgneal@695: bgneal@695: return render(request, 'user_photos/upload_form.html', { bgneal@695: 'enabled': uploads_enabled, bgneal@695: 'form': form, bgneal@695: }, bgneal@695: status=200 if uploads_enabled else 503)