summaryrefslogtreecommitdiff
path: root/scipy
diff options
context:
space:
mode:
Diffstat (limited to 'scipy')
-rw-r--r--scipy/forms.py54
-rw-r--r--scipy/views.py26
2 files changed, 48 insertions, 32 deletions
diff --git a/scipy/forms.py b/scipy/forms.py
index 281e929..2c13850 100644
--- a/scipy/forms.py
+++ b/scipy/forms.py
@@ -30,13 +30,49 @@ class UserProfileForm(UserChangeForm):
fields = ('first_name', 'last_name', 'email', 'username')
class DocumentUploadForm(forms.ModelForm):
- class Meta:
- model = Paper
- exclude = ('user', 'verified')
- widgets = {
- 'title':forms.TextInput(attrs={'placeholder':'Title of your Talk'}),
- 'objective':forms.TextInput(attrs={'placeholder':'Objective of the talk'}),
- 'abstract':forms.Textarea(attrs={'placeholder':'Abstract in 400 to 700 words'}),
- 'bio':forms.Textarea(attrs={'placeholder':'Tell us something about yourself in a few words'}),
- 'links':forms.TextInput(attrs={'placeholder':'Link to the code (if any) or relevant links'}),
+ links = forms.CharField(
+ required=False,
+ widget=forms.TextInput(attrs={'placeholder':'Link to the code (if any) or relevant links'})
+ )
+ attachments = forms.FileField(required=False)
+ class Meta:
+ model = Paper
+ exclude = ('user', 'verified')
+ widgets = {
+ 'title':forms.TextInput(attrs={'placeholder':'Title of your Talk'}),
+ 'objective':forms.TextInput(attrs={'placeholder':'Objective of the talk'}),
+ 'abstract':forms.Textarea(attrs={'placeholder':'Abstract in 400 to 700 words'}),
+ 'bio':forms.Textarea(attrs={'placeholder':'Tell us something about yourself in a few words'}),
}
+
+ def clean_attachments(self):
+ cleaned_data = self.cleaned_data
+ attachments = cleaned_data.get('attachments')
+ if attachments:
+ content_type = attachments.content_type.split('/')[1]
+ content_size = attachments.size
+ if not content_type in ['doc', 'docx', 'txt', 'pdf']:
+ raise forms.ValidationError('Only PDF, DOC, DOCX & TXT files are allowed')
+ elif content_size > 5242880:
+ raise forms.ValidationError('File size exceeds 5MB')
+ return attachments
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/scipy/views.py b/scipy/views.py
index c48dc11..7bb53a1 100644
--- a/scipy/views.py
+++ b/scipy/views.py
@@ -88,37 +88,17 @@ def upload_document(request):
if request.user.is_authenticated():
if request.method == 'POST':
form = DocumentUploadForm(request.POST, request.FILES)
- attachment = request.FILES['attachments']
- content_type = attachment.content_type.split('/')[1]
- content_size = attachment.size
- if not content_type in allowed_files:
- invalid_file_msg = "Only PDF, DOC, DOCX & TXT files are allowed"
- context['invalid_file'] = invalid_file_msg
- context['form'] = form
- context.update(csrf(request))
- return render_to_response('upload-document.html', context)
- elif 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)
- elif form.is_valid():
+ if form.is_valid():
data = form.save(commit=False)
data.user = request.user
data.verified = False
data.save()
return HttpResponseRedirect("/2013/call-for-proposals/?status=up")
- else:
- context = {}
- context.update(csrf(request))
- context['form'] = form
- context['current_user'] = request.user
- return render_to_response('upload-document.html', context)
else:
form = DocumentUploadForm()
context.update(csrf(request))
- context['form'] = DocumentUploadForm()
+ context['form'] = form
return render_to_response('upload-document.html', context)
else:
return HttpResponseRedirect('/2013/accounts/login')
+