forms.py
9.38 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
from django import forms
from django.utils.translation import ugettext_lazy as _
from .models import CourseCategory, Course, Subject, Topic, ActivityFile, Activity, FileMaterial, LinkMaterial
from s3direct.widgets import S3DirectWidget
from django_summernote.widgets import SummernoteWidget
class CategoryCourseForm(forms.ModelForm):
class Meta:
model = CourseCategory
fields = ('name',)
labels = {
'name': _('Name')
}
help_texts = {
'name': _('CourseCategory name')
}
class CourseForm(forms.ModelForm):
def clean_end_register_date(self):
init_register_date = self.cleaned_data['init_register_date']
end_register_date = self.cleaned_data['end_register_date']
if init_register_date and end_register_date and end_register_date < init_register_date:
raise forms.ValidationError(_('The end date may not be before the start date.'))
return end_register_date
def clean_init_date(self):
end_register_date = self.cleaned_data['end_register_date']
init_date = self.cleaned_data['init_date']
if end_register_date and init_date and init_date <= end_register_date:
raise forms.ValidationError(_('The course start date must be after the end of registration.'))
return init_date
def clean_end_date(self):
init_date = self.cleaned_data['init_date']
end_date = self.cleaned_data['end_date']
if init_date and end_date and end_date < init_date:
raise forms.ValidationError(_('The end date may not be before the start date.'))
return end_date
class Meta:
model = Course
fields = ('name', 'objectivies', 'content', 'max_students', 'init_register_date', 'end_register_date',
'init_date', 'end_date', 'category', 'coordenator','public')
labels = {
'name': _('Name'),
'objectivies': _('Objectives'),
'content': _('Content'),
'max_students': _('Number of studets maximum'),
'init_register_date': _('Course registration start date'),
'end_register_date': _('Course registration end date'),
'init_date': _('Course start date'),
'end_date': _('Course end date'),
'category': _('Category'),
'coordenator': _('Coordenator'),
'public':_('Public'),
}
help_texts = {
'name': _('Course name'),
'objectivies': _('Course objective'),
'content': _('Course modules'),
'max_students': _('Max number of students that a class can have'),
'init_register_date': _('Date that starts the registration period of the course (dd/mm/yyyy)'),
'end_register_date': _('Date that ends the registration period of the course (dd/mm/yyyy)'),
'init_date': _('Date that the course starts (dd/mm/yyyy)'),
'end_date': _('Date that the course ends (dd/mm/yyyy)'),
'category': _('CourseCategory which the course belongs'),
'coordenator': _('Course Coordenator'),
'public':_('To define if the course can be accessed by people not registered'),
}
widgets = {
'ategoy': forms.Select(),
'coordenator': forms.Select(),
'content': SummernoteWidget(),
'objectivies': SummernoteWidget(),
}
class UpdateCourseForm(CourseForm):
def clean_end_register_date(self):
init_register_date = self.cleaned_data['init_register_date']
end_register_date = self.cleaned_data['end_register_date']
if init_register_date and end_register_date and end_register_date < init_register_date:
raise forms.ValidationError(_('The end date may not be before the start date.'))
return end_register_date
def clean_init_date(self):
end_register_date = self.cleaned_data['end_register_date']
init_date = self.cleaned_data['init_date']
if end_register_date and init_date and init_date <= end_register_date:
raise forms.ValidationError(_('The course start date must be after the end of registration.'))
return init_date
def clean_end_date(self):
init_date = self.cleaned_data['init_date']
end_date = self.cleaned_data['end_date']
if init_date and end_date and end_date < init_date:
raise forms.ValidationError(_('The end date may not be before the start date.'))
return end_date
def __init__(self, *args, **kwargs):
super(UpdateCourseForm, self).__init__(*args, **kwargs)
self.fields["students"].required = False
class Meta:
model = Course
fields = ('name', 'objectivies', 'content', 'max_students', 'init_register_date', 'end_register_date',
'init_date', 'end_date', 'category','students', 'coordenator','public')
labels = {
'name': _('Name'),
'objectivies': _('Objectives'),
'content': _('Content'),
'max_students': _('Number of studets maximum'),
'init_register_date': _('Course registration start date'),
'end_register_date': _('Course registration end date'),
'init_date': _('Course start date'),
'end_date': _('Course end date'),
'category': _('Category'),
'coordenator': _('Coordenator'),
'students': _('Student'),
'public':_('Public'),
}
help_texts = {
'name': _('Course name'),
'objectivies': _('Course objective'),
'content': _('Course modules'),
'max_students': _('Max number of students that a class can have'),
'init_register_date': _('Date that starts the registration period of the course (dd/mm/yyyy)'),
'end_register_date': _('Date that ends the registration period of the course (dd/mm/yyyy)'),
'init_date': _('Date that the course starts (dd/mm/yyyy)'),
'end_date': _('Date that the course ends (dd/mm/yyyy)'),
'category': _('CourseCategory which the course belongs'),
'coordenator': _('Course Coordenator'),
'students': _("Course's Students"),
'public':_('To define if the course can be accessed by people not registered'),
}
widgets = {
'categoy': forms.Select(),
'coordenator': forms.Select(),
'content': SummernoteWidget(),
'objectivies': SummernoteWidget(),
}
class SubjectForm(forms.ModelForm):
class Meta:
model = Subject
fields = ('name', 'description','init_date', 'end_date', 'visible',)
labels = {
'name': _('Name'),
'description': _('Description'),
'init_date': _('Start date'),
'end_date': _('End date'),
'visible': _('Is it visible?'),
}
help_texts = {
'name': _("Subjects's name"),
'description': _("Subjects's description"),
'init_date': _('Start date of the subject'),
'end_date': _('End date of the subject'),
'visible': _('Is the subject visible?'),
}
widgets = {
'description':SummernoteWidget(),
}
class TopicForm(forms.ModelForm):
class Meta:
model = Topic
fields = ('name', 'description',)
labels = {
'name': _('Name'),
'description': _('Description'),
}
help_texts = {
'name': _("Topic's name"),
'description': _("Topic's description"),
}
widgets = {
'description':SummernoteWidget(),
}
class ActivityFileForm(forms.ModelForm):
name = forms.CharField(
required=False,
max_length=100,
widget=forms.TextInput(attrs={
'placeholder': 'Nome',
'class': 'form-control'
},
)
)
pdf = forms.URLField(required=True, widget=S3DirectWidget(
dest='activitys',
html=(
'<div class="s3direct" data-policy-url="{policy_url}">'
' <a class="file-link" target="_blank" href="{file_url}">{file_name}</a>'
' <a class="file-remove" href="#remove">Remover</a>'
' <input class="file-url" type="hidden" value="{file_url}" id="{element_id}" name="{name}" />'
' <input class="file-dest" type="hidden" value="{dest}">'
' <input class="file-input" type="file" />'
' <div class="progress">'
' <div class="progress-bar progress-bar-success progress-bar-striped active bar">'
' </div>'
' </div>'
'</div>'
)))
class Meta:
model = ActivityFile
fields = ['pdf','name']
class ActivityForm(forms.ModelForm):
class Meta:
model = Activity
fields = ['topic', 'limit_date', 'students','all_students']
class FileMaterialForm(forms.ModelForm):
class Meta:
model = FileMaterial
fields = ['name', 'file']
class LinkMaterialForm(forms.ModelForm):
class Meta:
model = LinkMaterial
fields = ['material', 'name', 'description','url']