forked from apluslms/a-plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexercise_forms.py
161 lines (126 loc) · 4.47 KB
/
exercise_forms.py
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
import logging
from django import forms
from django.utils.translation import ugettext_lazy as _
from course.models import CourseModule, LearningObjectCategory
from exercise.models import LearningObject, CourseChapter, BaseExercise, \
LTIExercise, StaticExercise, ExerciseWithAttachment
from .course_forms import FieldsetModelForm
logger = logging.getLogger("aplus.exercise")
COMMON_FIELDS = [
'status',
'category',
'course_module',
'parent',
'order',
'url',
]
SERVICE_FIELDS = [
'service_url',
'name',
'description',
]
EXERCISE_FIELDS = [
'max_submissions',
'max_points',
'points_to_pass',
'allow_assistant_viewing',
'allow_assistant_grading',
'min_group_size',
'max_group_size'
]
class LearningObjectMixin(object):
def init_fields(self, **kwargs):
self.lobject = kwargs.get('instance')
self.fields["category"].queryset = LearningObjectCategory.objects.filter(
course_instance=self.lobject.course_instance)
self.fields["course_module"].queryset = CourseModule.objects.filter(
course_instance=self.lobject.course_instance)
self.fields["parent"].queryset = LearningObject.objects\
.exclude(id=self.lobject.id)\
.filter(course_module=self.lobject.course_module)
@property
def remote_service_head(self):
return True
def get_hierarchy_fieldset(self):
return { 'legend':_('Hierarchy'), 'fields':self.get_fields('status',
'category','course_module','parent','order','url') }
def get_content_fieldset(self, *add):
return { 'legend':_('Content'), 'fields':self.get_fields('name',
'description', *add) }
class CourseChapterForm(LearningObjectMixin, FieldsetModelForm):
class Meta:
model = CourseChapter
fields = COMMON_FIELDS + SERVICE_FIELDS + [
'use_wide_column',
'generate_table_of_contents'
]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.init_fields(**kwargs)
def get_fieldsets(self):
return [
self.get_hierarchy_fieldset(),
self.get_content_fieldset('use_wide_column',
'generate_table_of_contents'),
]
class BaseExerciseForm(LearningObjectMixin, FieldsetModelForm):
class Meta:
model = BaseExercise
fields = COMMON_FIELDS + SERVICE_FIELDS + EXERCISE_FIELDS
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.init_fields(**kwargs)
def get_fieldsets(self):
return [
self.get_hierarchy_fieldset(),
self.get_content_fieldset(),
{ 'legend':_('Grading'), 'fields':self.get_fields('max_submissions',
'max_points','points_to_pass',
'allow_assistant_viewing','allow_assistant_grading') },
{ 'legend':_('Groups'), 'fields':self.get_fields('min_group_size',
'max_group_size') },
]
class LTIExerciseForm(BaseExerciseForm):
class Meta:
model = LTIExercise
fields = COMMON_FIELDS + SERVICE_FIELDS + EXERCISE_FIELDS + [
'lti_service',
'context_id',
'resource_link_id',
'resource_link_title',
'aplus_get_and_post',
]
@property
def remote_service_head(self):
return False
def get_content_fieldset(self):
return super().get_content_fieldset('lti_service','context_id',
'resource_link_id','resource_link_title',
'aplus_get_and_post','service_url')
class ExerciseWithAttachmentForm(BaseExerciseForm):
multipart = True
class Meta:
model = ExerciseWithAttachment
fields = COMMON_FIELDS + SERVICE_FIELDS + EXERCISE_FIELDS + [
'content',
'files_to_submit',
'attachment',
]
def get_content_fieldset(self):
return super().get_content_fieldset(
'content', 'files_to_submit', 'attachment')
class StaticExerciseForm(BaseExerciseForm):
class Meta:
model = StaticExercise
fields = COMMON_FIELDS + EXERCISE_FIELDS + [
'name',
'description',
'exercise_page_content',
'submission_page_content',
]
@property
def remote_service_head(self):
return False
def get_content_fieldset(self):
return super().get_content_fieldset(
'exercise_page_content', 'submission_page_content')