comparison 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
comparison
equal deleted inserted replaced
182:4a63f5d762a3 183:cdcbfaa65cfe
46 46
47 @login_required 47 @login_required
48 def index(request): 48 def index(request):
49 if request.method == 'POST': 49 if request.method == 'POST':
50 post_data = request.POST.copy() 50 post_data = request.POST.copy()
51 bundle = Bundle(uploader=request.user) 51 post_data['uploader'] = request.user.id
52 form = BundleForm(post_data, request.FILES, instance=bundle) 52 form = BundleForm(post_data, request.FILES)
53 53
54 if form.is_valid(): 54 if form.is_valid():
55 file = request.FILES.get('file') 55 file = request.FILES.get('file')
56 form.save() 56 bundle = form.save()
57 57
58 bundle.file_name = file.name 58 bundle.file_name = file.name
59 bundle.save() 59 bundle.save()
60 bundle_path = bundle.get_temp_path() 60 bundle_path = bundle.get_temp_path()
61 61