考试抽题
This commit is contained in:
parent
9c77679f92
commit
49eb0acc0e
|
@ -14,6 +14,7 @@
|
|||
<view class="weui-article__h2">{{tm_index+1}}.
|
||||
<span class="txlabel">{{tm_current.type}}</span>
|
||||
<span>({{tm_current.total_score}}分)</span>
|
||||
<span style="color:gray">({{tm_current.questioncat_name}})</span>
|
||||
</view>
|
||||
<view class="weui-article__title">{{tm_current.name}}</view>
|
||||
</view>
|
||||
|
|
|
@ -84,16 +84,34 @@ class WorkScopeViewSet(ModelViewSet):
|
|||
ret['panduan_count'] = workscope.rule.panduan_count
|
||||
ret['panduan_score'] = workscope.rule.panduan_score
|
||||
question_queryset = Question.objects.none()
|
||||
queryset = Question.objects.filter(is_delete=0,questioncat__in = workscope.questioncat.all())
|
||||
if ret['danxuan_count']:
|
||||
danxuan = queryset.filter(type='单选').order_by('?')[:ret['danxuan_count']]
|
||||
question_queryset = question_queryset | danxuan
|
||||
if ret['duoxuan_count']:
|
||||
duoxuan = queryset.filter(type='多选').order_by('?')[:ret['duoxuan_count']]
|
||||
question_queryset = question_queryset | duoxuan
|
||||
if ret['panduan_count']:
|
||||
panduan = queryset.filter(type='判断').order_by('?')[:ret['panduan_count']]
|
||||
question_queryset = question_queryset | panduan
|
||||
questioncats = workscope.questioncat.exclude(name='辐射小知识更新中').order_by('type')
|
||||
if questioncats.count() == 3:
|
||||
import random
|
||||
b2 = random.randint(1,9)
|
||||
b3 = random.randint(1,b2+1)
|
||||
b1 = 10 - b2 -b3
|
||||
a1 = 2*b2 + 2*b3 - 2
|
||||
a2 = 18 - 2*b2
|
||||
a3 = 24 - 2*b3
|
||||
queryset = Question.objects.filter(is_delete=0)
|
||||
a1_set = queryset.filter(questioncat=questioncats[0], type='单选').order_by('?')[:a1]
|
||||
a2_set = queryset.filter(questioncat=questioncats[1], type='单选').order_by('?')[:a2]
|
||||
a3_set = queryset.filter(questioncat=questioncats[2], type='单选').order_by('?')[:a3]
|
||||
b1_set = queryset.filter(questioncat=questioncats[0], type='多选').order_by('?')[:b1]
|
||||
b2_set = queryset.filter(questioncat=questioncats[1], type='多选').order_by('?')[:b2]
|
||||
b3_set = queryset.filter(questioncat=questioncats[2], type='多选').order_by('?')[:b3]
|
||||
question_queryset = question_queryset|a1_set|a2_set|a3_set|b1_set|b2_set|b3_set
|
||||
else:
|
||||
queryset = Question.objects.filter(is_delete=0,questioncat__in = workscope.questioncat.all())
|
||||
if ret['danxuan_count']:
|
||||
danxuan = queryset.filter(type='单选').order_by('?')[:ret['danxuan_count']]
|
||||
question_queryset = question_queryset | danxuan
|
||||
if ret['duoxuan_count']:
|
||||
duoxuan = queryset.filter(type='多选').order_by('?')[:ret['duoxuan_count']]
|
||||
question_queryset = question_queryset | duoxuan
|
||||
if ret['panduan_count']:
|
||||
panduan = queryset.filter(type='判断').order_by('?')[:ret['panduan_count']]
|
||||
question_queryset = question_queryset | panduan
|
||||
questions = QuestionSerializer(instance=question_queryset.order_by('type'),many=True).data
|
||||
for i in questions:
|
||||
if i['type'] == '单选':
|
||||
|
|
Loading…
Reference in New Issue