summaryrefslogtreecommitdiff
path: root/scipy/views.py
diff options
context:
space:
mode:
authorhardythe12013-10-23 15:09:49 +0530
committerhardythe12013-10-23 15:09:49 +0530
commitcbc26418b2b7f73628ed00aa19dfc1210839402f (patch)
tree93ebabccd6d70321021cf47592de011990defae8 /scipy/views.py
parent62f9a803bdf9b5175823621189b2a8b6073da551 (diff)
downloadSciPy2013-cbc26418b2b7f73628ed00aa19dfc1210839402f.tar.gz
SciPy2013-cbc26418b2b7f73628ed00aa19dfc1210839402f.tar.bz2
SciPy2013-cbc26418b2b7f73628ed00aa19dfc1210839402f.zip
changes to receive file less than 5MB only
Diffstat (limited to 'scipy/views.py')
-rw-r--r--scipy/views.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/scipy/views.py b/scipy/views.py
index f77c467..d142e76 100644
--- a/scipy/views.py
+++ b/scipy/views.py
@@ -82,17 +82,25 @@ def user_profile(request):
def upload_document(request):
allowed_files = ['doc', 'docx', 'txt', 'pdf']
invalid_file_msg = None
+ large_file_msg = None
context = {}
+ context['current_user'] = request.user
if request.user.is_authenticated():
if request.method == 'POST':
form = DocumentUploadForm(request.POST, request.FILES)
content_type = request.FILES['attachments'].content_type.split('/')[1]
+ content_size = request.FILES['attachments'].size
if not content_type in allowed_files:
invalid_file_msg = "Only PDF, DOC, DOCX & TXT files are allowed"
- context['current_user'] = request.user
context['invalid_file'] = invalid_file_msg
+ context['form'] = form
context.update(csrf(request))
+ return render_to_response('upload-document.html', context)
+ if content_size > 5242880:
+ large_file_msg = "File size exceeds 5MB"
+ context['large_file'] = large_file_msg
context['form'] = form
+ context.update(csrf(request))
return render_to_response('upload-document.html', context)
if form.is_valid():
data = form.save(commit=False)
@@ -110,8 +118,6 @@ def upload_document(request):
form = DocumentUploadForm()
context.update(csrf(request))
context['form'] = DocumentUploadForm()
- context['current_user'] = request.user
- context['invalid_file'] = invalid_file_msg
return render_to_response('upload-document.html', context)
else:
return HttpResponseRedirect('/2013/accounts/login')