This commit is contained in:
caoqianming 2024-08-27 10:50:25 +08:00
commit ab5472bda3
5 changed files with 40 additions and 35 deletions

View File

@ -70,6 +70,12 @@
<el-table-column align="left" label="所属考试"> <el-table-column align="left" label="所属考试">
<template slot-scope="scope">{{ scope.row.exam_name }}</template> <template slot-scope="scope">{{ scope.row.exam_name }}</template>
</el-table-column> </el-table-column>
<el-table-column align="left" label="是否通过" sortable='custom' prop="is_pass">
<template slot-scope="scope">
<el-tag v-if="scope.row.is_pass" type="success"></el-tag>
<el-tag v-else type="danger"></el-tag>
</template>
</el-table-column>
<el-table-column align="left" label="得分" sortable='custom' prop="score"> <el-table-column align="left" label="得分" sortable='custom' prop="score">
<template slot-scope="scope">{{ scope.row.score }}</template> <template slot-scope="scope">{{ scope.row.score }}</template>
</el-table-column> </el-table-column>

View File

@ -19,7 +19,7 @@ function request(url, method, data) {
} }
else { else {
var msg = '请求错误' var msg = '请求错误'
if(res.data.msg){ if(res.data.msg && typeof(res.data.msg) == "string"){
msg = res.data.msg msg = res.data.msg
} }
if (msg.indexOf('该操作的权限')!=-1){ if (msg.indexOf('该操作的权限')!=-1){

View File

@ -551,38 +551,32 @@ class ExamTestViewSet(PageOrNot, ModelViewSet):
@transaction.atomic @transaction.atomic
def create(self, request, *args, **kwargs): def create(self, request, *args, **kwargs):
serializer = MoniTestSerializer(data = request.data) serializer = MoniTestSerializer(data = request.data)
if serializer.is_valid(): serializer.is_valid(raise_exception=True)
instance = serializer.save(consumer = request.user) instance = serializer.save(consumer = request.user)
if 'questions' in request.data: if 'questions' in request.data:
questions = [] questions = []
for i in request.data['questions']: for i in request.data['questions']:
question = {} question = {}
question['question'] = i['id'] question['question'] = i['id']
question['examtest'] = instance.id question['examtest'] = instance.id
question['score'] = i['score'] question['score'] = i['score']
if 'user_answer' in i: if 'user_answer' in i:
question['user_answer'] = i['user_answer'] question['user_answer'] = i['user_answer']
question['is_right'] = i['is_right'] question['is_right'] = i['is_right']
questions.append(question) questions.append(question)
serializer_detail = AnswerDetailCreateSerializer(data=questions, many=True) serializer_detail = AnswerDetailCreateSerializer(data=questions, many=True)
if serializer_detail.is_valid(): serializer_detail.is_valid(raise_exception=True)
serializer_detail.save() serializer_detail.save()
# 关联正式考试如有 # 关联正式考试如有
if request.data.get('exam', None): if request.data.get('exam', None):
exam = Exam.objects.get(pk=request.data['exam']) exam = Exam.objects.get(pk=request.data['exam'])
instance.exam = exam instance.exam = exam
instance.save() instance.save()
# 自动发证 # 自动发证
if exam.auto_issue and instance.is_pass: if exam.auto_issue and instance.is_pass:
issue(instance) issue(instance)
return Response(MoniTestSerializer(instance).data,status=status.HTTP_200_OK) return Response(MoniTestSerializer(instance).data,status=status.HTTP_200_OK)
else: raise ParseError('答题记录不存在')
return Response(serializer_detail.errors)
else:
return Response({'error':'答题记录不存在'})
else:
return Response(serializer.errors)
@action(methods=['get'], detail=False, @action(methods=['get'], detail=False,
url_path='export', url_name='export_test', perms_map=[{'*':'export_test'}]) url_path='export', url_name='export_test', perms_map=[{'*':'export_test'}])
@ -645,6 +639,7 @@ class PaperViewSet(PageOrNot, ModelViewSet):
instance = serializer.save() instance = serializer.save()
if 'questions' in data: if 'questions' in data:
questions = [] questions = []
Question.objects.get_queryset(all=True).filter(is_delete=True, id__in=[i['id'] for i in data['questions']]).update(is_delete=False)
for i in data['questions']: for i in data['questions']:
question = {} question = {}
question['question'] = i['id'] question['question'] = i['id']
@ -669,6 +664,7 @@ class PaperViewSet(PageOrNot, ModelViewSet):
self.perform_update(serializer) self.perform_update(serializer)
if 'questions' in data: if 'questions' in data:
questions = [] questions = []
Question.objects.get_queryset(all=True).filter(is_delete=True, id__in=[i['id'] for i in data['questions']]).update(is_delete=False)
for i in data['questions']: for i in data['questions']:
question = {} question = {}
question['question'] = i['id'] question['question'] = i['id']

View File

@ -32,14 +32,15 @@ class SoftDeletableManagerMixin(object):
""" """
_queryset_class = SoftDeletableQuerySet _queryset_class = SoftDeletableQuerySet
def get_queryset(self): def get_queryset(self, all=False):
""" """
Return queryset limited to not deleted entries. Return queryset limited to not deleted entries.
""" """
kwargs = {'model': self.model, 'using': self._db} kwargs = {'model': self.model, 'using': self._db}
if hasattr(self, '_hints'): if hasattr(self, '_hints'):
kwargs['hints'] = self._hints kwargs['hints'] = self._hints
if all:
return self._queryset_class(**kwargs)
return self._queryset_class(**kwargs).filter(is_delete=False) return self._queryset_class(**kwargs).filter(is_delete=False)

View File

@ -50,6 +50,8 @@ class FitJSONRenderer(JSONRenderer):
data = data[list(data.keys())[0]] data = data[list(data.keys())[0]]
if isinstance(data, list): if isinstance(data, list):
data = data[0] data = data[0]
if not isinstance(data, str):
data = '请求错误'
response_body.msg = data response_body.msg = data
elif data and 'error' in data and data['error']:# 自传异常,key为error elif data and 'error' in data and data['error']:# 自传异常,key为error
response_body.code = data.get("code",400) response_body.code = data.get("code",400)