File tree Expand file tree Collapse file tree 2 files changed +6
-20
lines changed Expand file tree Collapse file tree 2 files changed +6
-20
lines changed Original file line number Diff line number Diff line change @@ -60,13 +60,17 @@ def get_answers_content(self):
60
60
return answers
61
61
62
62
def check_answer (self , answer ):
63
+ # NOTE: don't use .values_list('content', flat=True) here,
64
+ # because it will not utilize .prefetch_related('answers'),
65
+ # which lead to more DB queries
63
66
possible_answers = self .answers .all ()
67
+ possible_answers = [answer .content for answer in possible_answers ]
64
68
65
69
if self .is_fill_blank ():
66
70
answer = f' { answer } ' # Add 2 spaces to both side to help with regex matching
67
71
68
72
for correct_answer in possible_answers :
69
- regex = correct_answer . content
73
+ regex = correct_answer
70
74
if regex .startswith ('(' ):
71
75
regex = r'(?:' + regex [1 :]
72
76
Original file line number Diff line number Diff line change 1
- from copy import copy
2
-
3
1
from django .utils .translation import gettext as _
4
2
from rest_framework import serializers
5
- from rest_framework .reverse import reverse
6
3
7
4
from account .serializers import UserSerializer
8
5
from classroom .models import Classroom
9
6
from classroom .utils .serializer import ValidateUniqueTogetherMixin
10
7
11
8
12
- class _StudentSerializer (UserSerializer ):
13
- reading_report_url = serializers .SerializerMethodField ()
14
-
15
- class Meta (UserSerializer .Meta ):
16
- fields = copy (UserSerializer .Meta .fields )
17
- fields .append ('reading_report_url' )
18
-
19
- def get_reading_report_url (self , student ):
20
- request = self .context ['request' ]
21
- classroom_pk = self .context ['view' ].kwargs ['pk' ]
22
- url = reverse ('classroom-student-reading-report' , kwargs = {'pk' : classroom_pk }, request = request )
23
- url += f'?student={ student .pk } '
24
- return url
25
-
26
-
27
9
class ClassroomSerializer (ValidateUniqueTogetherMixin , serializers .HyperlinkedModelSerializer ):
28
10
teacher = UserSerializer (read_only = True )
29
- students = _StudentSerializer (many = True , read_only = True )
11
+ students = UserSerializer (many = True , read_only = True )
30
12
31
13
class Meta :
32
14
model = Classroom
You can’t perform that action at this time.
0 commit comments