This repository was archived by the owner on Aug 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathforms.py
More file actions
177 lines (139 loc) · 4.46 KB
/
Copy pathforms.py
File metadata and controls
177 lines (139 loc) · 4.46 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import re
from PIL import Image
from .models import (
Generator,
GsocEndDateDefault,
GsocStartDate,
ArticleReview,
UserDetails,
UserProfile,
RegLink,
BlogPostDueDate,
Event,
SubOrgDetails,
SubOrg,
GsocEndDate,
User
)
from django import forms
from django.core.exceptions import ValidationError
class UserProfileForm(forms.ModelForm):
class Meta:
model = UserProfile
fields = (
"role",
"suborg_full_name",
"gsoc_year",
"accepted_proposal_pdf",
"app_config",
"hidden",
)
widgets = {"app_config": forms.Select()}
class ProposalUploadForm(forms.ModelForm):
class Meta:
model = UserProfile
fields = ["accepted_proposal_pdf"]
class UserDetailsForm(forms.ModelForm):
class Meta:
model = UserDetails
fields = ("deactivation_date",)
class RegLinkForm(forms.ModelForm):
class Meta:
model = RegLink
fields = ("email", "user_role", "user_suborg", "gsoc_end_date", "gsoc_year")
class BlogPostDueDateForm(forms.ModelForm):
class Meta:
model = BlogPostDueDate
fields = ("category", "date", "title")
class EventForm(forms.ModelForm):
class Meta:
model = Event
fields = ("title", "start_date", "end_date")
class GsocEndDateForm(forms.ModelForm):
class Meta:
model = GsocEndDate
fields = ("date",)
class GsocStartDateForm(forms.ModelForm):
class Meta:
model = GsocStartDate
fields = ("date",)
class GsocEndDateStandardForm(forms.ModelForm):
class Meta:
model = GsocEndDateDefault
fields = ("date",)
class GeneratorForm(forms.ModelForm):
class Meta:
model = Generator
fields = ("category", "start", "recurDays")
class ChangeInfoForm(forms.ModelForm):
class Meta:
model = User
fields = ("email", "first_name", "last_name")
class AcceptanceForm(forms.Form):
email = forms.EmailField()
password = forms.CharField(widget=forms.PasswordInput())
reglink = forms.CharField(widget=forms.HiddenInput())
class ArticleReviewForm(forms.ModelForm):
class Meta:
model: ArticleReview
fields = ("article", "is_reviewed", "last_reviewed_by")
class SubOrgApplicationForm(forms.ModelForm):
class Meta:
model = SubOrgDetails
exclude = (
"accepted",
"last_message",
"changed",
"last_reviewed_at",
"last_reviewed_by",
"created_at",
"updated_at",
)
widgets = {
"suborg_admin": forms.HiddenInput(),
"suborg_admin_email": forms.HiddenInput(),
"gsoc_year": forms.HiddenInput(),
}
def clean(self):
cd = self.cleaned_data
past_exp = cd.get("past_gsoc_experience")
suborg_name = cd.get("suborg_name")
suborg = cd.get("suborg")
logo = cd.get("logo")
try:
im = Image.open(logo)
width, height = im.size
if width != 256 or height != 256:
raise ValidationError("The image should of size 256 x 256 pixels")
except:
raise ValidationError("You must have a logo")
contact = [
cd.get("chat", None),
cd.get("mailing_list", None),
cd.get("twitter_url", None),
cd.get("blog_url", None),
cd.get("homepage", None),
]
contact = list(filter(lambda a: a is not None, contact))
if not suborg and suborg_name:
suborg = SubOrg.objects.filter(suborg_name=suborg_name)
if suborg:
cd["suborg"] = suborg.first()
else:
regex = r'^[ a-zA-Z\-]*$'
if not re.match(regex, suborg_name):
raise ValidationError("Invalid suborg name.")
elif suborg and not suborg_name:
cd["suborg_name"] = suborg.suborg_name
elif suborg and suborg_name:
if suborg.suborg_name != suborg_name:
raise ValidationError("Inconsistent suborg field values")
else:
raise ValidationError(
"Either suborg should be selected or " "the suborg name"
)
if len(contact) < 1:
raise ValidationError(
"At least one out of the five contact " "details should be entered"
)
return cd