diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/user_photos/views.py	Sat Sep 07 20:50:46 2013 -0500
@@ -0,0 +1,38 @@
+"""Views for the user_photos application."""
+from django.conf import settings
+from django.contrib.auth.decorators import login_required
+from django.shortcuts import render
+
+from user_photos.forms import UploadForm
+
+
+@login_required
+def upload(request):
+    """This view function receives an uploaded image file from a user.
+    The photo will be resized if necessary and a thumbnail image will be
+    created. The image and thumbnail will then be uploaded to the Amazon
+    S3 service for storage.
+
+    TODO: rate limiting
+          pass off the processing to a celery task
+          ajax version of this view
+
+    """
+    form = None
+    uploads_enabled = settings.USER_PHOTO_ENABLED
+
+    if uploads_enabled:
+        if request.method == 'POST':
+            form = UploadForm(request.POST, request.FILES)
+            if form.is_valid():
+                #TODO
+                print "**************", request.FILES['image_file']
+                pass
+        else:
+            form = UploadForm()
+
+    return render(request, 'user_photos/upload_form.html', {
+        'enabled': uploads_enabled,
+        'form': form,
+        },
+        status=200 if uploads_enabled else 503)