summaryrefslogtreecommitdiff
path: root/scipy/forms.py
blob: 2c13850d5b60d28d7f9bb9317008cebb287a31b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from django import forms
from django.db import models
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm, UserChangeForm

from website.models import Paper

class UserLoginForm(forms.Form):
	username = forms.CharField(
			widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Username'}), 
			label=''
		)
	password = forms.CharField(
			widget=forms.PasswordInput(attrs={'class': 'form-control', 'placeholder': 'Password'}), 
			label=''
		)
	
class UserRegisterForm(UserCreationForm):

	class Meta:
		model = User
		fields = ('first_name', 'last_name', 'email', 'username', 'password1', 'password2')


class UserProfileForm(UserChangeForm):
	password = forms.CharField(widget=forms.PasswordInput())
	password1 = forms.CharField(widget=forms.PasswordInput())
	class Meta:
		model = User
		fields = ('first_name', 'last_name', 'email', 'username')

class DocumentUploadForm(forms.ModelForm):
    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