forms.py
4.59 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
from amadeus import settings
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):
class Meta:
model = Course
fields = ('name', 'category', 'coordenator','public')
labels = {
'name': _('Name'),
'category': _('Category'),
'coordenator': _('Coordenator'),
'public':_('Public'),
}
help_texts = {
'name': _('Course name'),
'coordenator': _('Course Coordenator'),
'public':_('To define if the course can be accessed by people not registered'),
}
widgets = {
'category': forms.Select(),
'coordenator': forms.Select(),
}
class UpdateCourseForm(CourseForm):
class Meta:
model = Course
fields = ('name', 'category', 'coordenator','public')
labels = {
'name': _('Name'),
'category': _('Category'),
'coordenator': _('Coordenator'),
'public':_('Public'),
}
help_texts = {
'name': _('Course name'),
'coordenator': _('Course Coordenator'),
'public':_('To define if the course can be accessed by people not registered'),
}
widgets = {
'category': forms.Select(),
'coordenator': forms.Select(),
}
class SubjectForm(forms.ModelForm):
init_date = forms.DateField(input_formats=settings.DATE_INPUT_FORMATS)
end_date = forms.DateField(input_formats=settings.DATE_INPUT_FORMATS)
def clean_end_date(self):
end_date = self.cleaned_data['end_date']
if('init_date' in self.cleaned_data):
init_date = self.cleaned_data['init_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 = Subject
fields = ('name', 'description','init_date', 'end_date', 'visible','students',)
localized_fields = ('init_date', 'end_date',)
labels = {
'name': _('Name'),
'description': _('Description'),
'init_date': _('Start date'),
'end_date': _('End date'),
'visible': _('Is it visible?'),
'students': _('Students')
}
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?'),
'students': _('The students that can participate in this subject. Hold down the "Control", or "Command" on the Mac, to select more than one option.')
}
widgets = {
'description':SummernoteWidget(),
}
class TopicForm(forms.ModelForm):
class Meta:
model = Topic
fields = ('name', 'description','visible')
labels = {
'name': _('Name'),
'description': _('Description'),
'visible': _('Is the topic visible?'),
}
help_texts = {
'name': _("Topic's name"),
'description': _("Topic's description"),
'visible': _('Is it visible?'),
}
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']