diff apps/bundle/views.py @ 183:cdcbfaa65cfe

Catch integrity error when creating bundles If the user has already created a bundle with that name, then the form should raise a ValidationError instead of showing a 500.
author dellsystem <ilostwaldo@gmail.com>
date Sat, 27 Oct 2012 15:41:58 -0400
parents 86129d185ddb
children a4f88ac85837 4033ebe1867f
line wrap: on
line diff
--- a/apps/bundle/views.py	Sat Oct 27 15:40:33 2012 -0400
+++ b/apps/bundle/views.py	Sat Oct 27 15:41:58 2012 -0400
@@ -48,12 +48,12 @@
 def index(request):
     if request.method == 'POST':
         post_data = request.POST.copy()
-        bundle = Bundle(uploader=request.user)
-        form = BundleForm(post_data, request.FILES, instance=bundle)
+        post_data['uploader'] = request.user.id
+        form = BundleForm(post_data, request.FILES)
 
         if form.is_valid():
             file = request.FILES.get('file')
-            form.save()
+            bundle = form.save()
 
             bundle.file_name = file.name
             bundle.save()