Skip to content

Commit 2230615

Browse files
fixbug marking score
1 parent be52683 commit 2230615

File tree

2 files changed

+6
-20
lines changed

2 files changed

+6
-20
lines changed

classroom/models/abstracts/question.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,17 @@ def get_answers_content(self):
6060
return answers
6161

6262
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
6366
possible_answers = self.answers.all()
67+
possible_answers = [answer.content for answer in possible_answers]
6468

6569
if self.is_fill_blank():
6670
answer = f' {answer} ' # Add 2 spaces to both side to help with regex matching
6771

6872
for correct_answer in possible_answers:
69-
regex = correct_answer.content
73+
regex = correct_answer
7074
if regex.startswith('('):
7175
regex = r'(?:' + regex[1:]
7276

classroom/serializers/classroom.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,14 @@
1-
from copy import copy
2-
31
from django.utils.translation import gettext as _
42
from rest_framework import serializers
5-
from rest_framework.reverse import reverse
63

74
from account.serializers import UserSerializer
85
from classroom.models import Classroom
96
from classroom.utils.serializer import ValidateUniqueTogetherMixin
107

118

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-
279
class ClassroomSerializer(ValidateUniqueTogetherMixin, serializers.HyperlinkedModelSerializer):
2810
teacher = UserSerializer(read_only=True)
29-
students = _StudentSerializer(many=True, read_only=True)
11+
students = UserSerializer(many=True, read_only=True)
3012

3113
class Meta:
3214
model = Classroom

0 commit comments

Comments
 (0)