summaryrefslogtreecommitdiff
path: root/scipy/views.py
diff options
context:
space:
mode:
authorhardythe12013-10-23 14:47:47 +0530
committerhardythe12013-10-23 14:47:47 +0530
commitf14944ec56d733065d652d8e94d27b2c6ead2a4c (patch)
treea6c722d20ccc3af14aea5b3d8de5b553c2f612aa /scipy/views.py
parent22e294c1c8012f14ba5676d9d9713dda4cb1c4e2 (diff)
downloadSciPy2013-f14944ec56d733065d652d8e94d27b2c6ead2a4c.tar.gz
SciPy2013-f14944ec56d733065d652d8e94d27b2c6ead2a4c.tar.bz2
SciPy2013-f14944ec56d733065d652d8e94d27b2c6ead2a4c.zip
updated view to receive only pdf, txt, doc & docx file
Diffstat (limited to 'scipy/views.py')
-rw-r--r--scipy/views.py24
1 files changed, 19 insertions, 5 deletions
diff --git a/scipy/views.py b/scipy/views.py
index 25932ff..f77c467 100644
--- a/scipy/views.py
+++ b/scipy/views.py
@@ -49,15 +49,19 @@ def user_logout(request):
# User Register View
def user_register(request):
+ context = {}
if request.user.is_anonymous():
if request.method == 'POST':
form = UserRegisterForm(request.POST)
- if form.is_valid:
+ if form.is_valid():
form.save()
- return HttpResponseRedirect('/2013/accounts/upload-document')
+ return HttpResponseRedirect('/2013/accounts/upload-document')
+ else:
+ context.update(csrf(request))
+ context['form'] = form
+ return render_to_response('register.html', context)
else:
form = UserRegisterForm()
- context = {}
context.update(csrf(request))
context['form'] = form
return render_to_response('register.html', context)
@@ -76,9 +80,20 @@ def user_profile(request):
# Document Upload View
def upload_document(request):
+ allowed_files = ['doc', 'docx', 'txt', 'pdf']
+ invalid_file_msg = None
+ context = {}
if request.user.is_authenticated():
if request.method == 'POST':
form = DocumentUploadForm(request.POST, request.FILES)
+ content_type = request.FILES['attachments'].content_type.split('/')[1]
+ 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.update(csrf(request))
+ context['form'] = form
+ return render_to_response('upload-document.html', context)
if form.is_valid():
data = form.save(commit=False)
data.user = request.user
@@ -93,11 +108,10 @@ def upload_document(request):
return render_to_response('upload-document.html', context)
else:
form = DocumentUploadForm()
-
- context = {}
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')