summaryrefslogtreecommitdiff
path: root/website/forms.py
blob: 870c54afc5ebbd73f0a877f13448da7ee47a181d (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
from django import forms
from django.db import models
from django.contrib.auth.models import User
from django.contrib.auth import login, logout, authenticate
from django.core.validators import validate_email
from django.contrib.auth.forms import UserCreationForm
from website.models import Proposal
from django.core.validators import MinLengthValidator, MinValueValidator, \
RegexValidator, URLValidator


class CommentForm(forms.Form):
    pass

class ProposalForm(forms.ModelForm):
    error_css_class = 'error'
    required_css_class = 'required'

    # content_link = forms.CharField(required=False, help_text='Link to the content of your Talk')
    # speaker_link = forms.CharField(required=False, help_text='Link to information about the Speaker')
    about_me = forms.CharField(widget=forms.Textarea(attrs={'class': 'form-control', 'placeholder': 'About Me'}),
                        required = True,
                        error_messages = {'required':'Title field required.'},  
                        label = '')
    attachment = forms.FileField(widget=forms.ClearableFileInput(attrs={'multiple': True}))   
    phone = forms.CharField(max_length = 12, widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Phone'}),required=False, label = '', validators = [RegexValidator(regex = '^[0-9-_+.]*$')])
    title = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Title'}),
                        required = True,
                        error_messages = {'required':'Title field required.'},  
                        label = ''
                        )
    abstract = forms.CharField(widget=forms.Textarea(attrs={'class': 'form-control', 'placeholder': 'Abstract'}),
                        required = True,
                        error_messages = {'required':'Title field required.'},  
                        label = ''
                        )
    class Meta:
        model = Proposal
        exclude = ('user', 'email','prerequisite','status')

    def clean_title(self):
        title = self.cleaned_data['title']
        if Proposal.objects.filter(title=title).exists():
            raise forms.ValidationError("This title already exist.")
        return title

    def clean_attachment(self):
        import os
        cleaned_data = self.cleaned_data
        attachment = cleaned_data.get('attachment', None)
        if attachment:
            ext = os.path.splitext(attachment.name)[1]
            valid_extensions = ['.pdf','.zip','.rar']
            if not ext in valid_extensions:
                raise forms.ValidationError(u'File not supported!')
            if attachment.size > (5*1024*1024):
                raise forms.ValidationError('File size exceeds 5MB')
        return attachment


class WorkshopForm(forms.ModelForm):
    # content_link = forms.CharField(required=False, help_text='Link to the content of your Talk')
    # speaker_link = forms.CharField(required=False, help_text='Link to information about the Speaker')
    about_me = forms.CharField(widget=forms.Textarea(attrs={'class': 'form-control', 'placeholder': 'About Me'}),
                        required = True,
                        error_messages = {'required':'Title field required.'},  
                        label = '')
    attachment = forms.FileField(widget=forms.ClearableFileInput(attrs={'multiple': True}))   
    phone = forms.CharField(max_length = 12, widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Phone'}),required=False, label = '', validators = [RegexValidator(regex = '^[0-9-_+.]*$')])
    title = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Title'}),
                        required = True,
                        error_messages = {'required':'Title field required.'},  
                        label = ''
                        )
    abstract = forms.CharField(widget=forms.Textarea(attrs={'class': 'form-control', 'placeholder': 'Abstract'}),
                        required = True,
                        error_messages = {'required':'Title field required.'},  
                        label = ''
                        )
    prerequisite = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Prerequisite'}),
                        required = True,
                        error_messages = {'required':'Title field required.'},  
                        label = ''
                        )
    class Meta:
        model = Proposal
        exclude = ('user', 'email','status')

    def clean_title(self):
        title = self.cleaned_data['title']
        if Proposal.objects.filter(title=title).exists():
            raise forms.ValidationError("This title already exist.")
        return title


class UserRegisterForm(UserCreationForm):
	class Meta:
		model = User
		fields = ('first_name', 'last_name', 'email', 'username', 'password1',
		          'password2')
        first_name = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'First Name'}),
                        label = ''
                        )
        last_name = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Last Name'}),
                        label = ''
                        )
        email = forms.EmailField(widget=forms.TextInput(attrs={'placeholder': 'Email'}),
                        required = True,
                        error_messages = {'required':'Email field required.'},  
                        label = ''
                        )
        username = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Username'}),
                        required = True,
                        error_messages = {'required':'Username field required.'},  
                        label = ''
                        )
        password1 = forms.CharField(widget=forms.PasswordInput(attrs={'placeholder': 'Password'}),
                        required = True,
                        error_messages = {'required':'Password field required.'},  
                        label = ''
                        )
        password2 = forms.CharField(widget=forms.PasswordInput(attrs={'placeholder': 'Confirm Password'}),
                        required = True,
                        error_messages = {'required':'Password Confirm field required.'},  
                        label = ''
                        )


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=''
		)