summaryrefslogtreecommitdiff
path: root/scipy/forms.py
diff options
context:
space:
mode:
Diffstat (limited to 'scipy/forms.py')
-rw-r--r--scipy/forms.py54
1 files changed, 45 insertions, 9 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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+