forms.py
1 |
|
2 |
from django.forms import ModelForm, modelformset_factory, TextInput |
3 |
from . import models |
4 |
import administration |
5 |
|
6 |
class AssignmentForm(ModelForm): |
7 |
class Meta: |
8 |
model = models.Assignment |
9 |
fields = ['title', |
10 |
'information', |
11 |
'deadline', |
12 |
'digital_task', |
13 |
] |
14 |
class AnnouncementForm(ModelForm): |
15 |
class Meta: |
16 |
model = models.Announcement |
17 |
fields = ['title', |
18 |
'text', |
19 |
] |
20 |
class UploadForm(ModelForm): |
21 |
class Meta: |
22 |
model = models.Upload |
23 |
fields = ['comment', |
24 |
'file', |
25 |
] |
26 |
class CourseItemForm(ModelForm): |
27 |
class Meta: |
28 |
model = models.CourseItem |
29 |
fields = ['file', |
30 |
'note', |
31 |
] |
32 |
|
33 |
AssignmentFormSet = modelformset_factory( |
34 |
models.Assignment, fields=('title', 'information', 'deadline', 'digital_task'), |
35 |
localized_fields="__all__", |
36 |
can_delete=True, |
37 |
) |
38 |
AnnouncementFormSet = modelformset_factory( |
39 |
models.Announcement, fields=('title', 'text'), |
40 |
localized_fields="__all__", |
41 |
can_delete=True, |
42 |
) |
43 |
CourseItemFormSet = modelformset_factory( |
44 |
models.CourseItem, fields=('file', 'note'), |
45 |
localized_fields="__all__", |
46 |
can_delete=True, |
47 |
) |
48 |
CourseResultFormSet = modelformset_factory( |
49 |
administration.models.CourseResult, fields=('student', 'first_score', 'second_score', 'result'), |
50 |
localized_fields="__all__", |
51 |
can_delete=False, |
52 |
extra=0, |
53 |
# XXX: What about this commented widget? |
54 |
# It was supposed to be that the student couldn't be altered, but that per name |
55 |
# would be displayed in a disabled field. However Django for one reason or another |
56 |
# can't FOR THE LOVE OF GOD handle a changed widget like this. So it's disabled |
57 |
# and currently Joeni relies on the users to /not/ edit an editable field. Slick. |
58 |
#widgets={'student': TextInput(attrs={'disabled':'true', 'readonly':'readonly'})}, |
59 |
) |
60 |
UploadFormSet = modelformset_factory( |
61 |
models.Upload, fields=('file', 'comment'), |
62 |
localized_fields="__all__", |
63 |
can_delete=True, |
64 |
) |
65 |