diff --git a/test_client/src/views/analyse/examtest2.vue b/test_client/src/views/analyse/examtest2.vue
index 820a728..39ba084 100644
--- a/test_client/src/views/analyse/examtest2.vue
+++ b/test_client/src/views/analyse/examtest2.vue
@@ -70,6 +70,12 @@
{{ scope.row.exam_name }}
+
+
+ 是
+ 否
+
+
{{ scope.row.score }}
diff --git a/test_mini/utils/request.js b/test_mini/utils/request.js
index 8c498f2..c28a49e 100644
--- a/test_mini/utils/request.js
+++ b/test_mini/utils/request.js
@@ -19,7 +19,7 @@ function request(url, method, data) {
}
else {
var msg = '请求错误'
- if(res.data.msg){
+ if(res.data.msg && typeof(res.data.msg) == "string"){
msg = res.data.msg
}
if (msg.indexOf('该操作的权限')!=-1){
diff --git a/test_server/examtest/views.py b/test_server/examtest/views.py
index 44975a8..29cfdce 100644
--- a/test_server/examtest/views.py
+++ b/test_server/examtest/views.py
@@ -551,38 +551,32 @@ class ExamTestViewSet(PageOrNot, ModelViewSet):
@transaction.atomic
def create(self, request, *args, **kwargs):
serializer = MoniTestSerializer(data = request.data)
- if serializer.is_valid():
- instance = serializer.save(consumer = request.user)
- if 'questions' in request.data:
- questions = []
- for i in request.data['questions']:
- question = {}
- question['question'] = i['id']
- question['examtest'] = instance.id
- question['score'] = i['score']
- if 'user_answer' in i:
- question['user_answer'] = i['user_answer']
- question['is_right'] = i['is_right']
- questions.append(question)
- serializer_detail = AnswerDetailCreateSerializer(data=questions, many=True)
- if serializer_detail.is_valid():
- serializer_detail.save()
- # 关联正式考试如有
- if request.data.get('exam', None):
- exam = Exam.objects.get(pk=request.data['exam'])
- instance.exam = exam
- instance.save()
- # 自动发证
- if exam.auto_issue and instance.is_pass:
- issue(instance)
- return Response(MoniTestSerializer(instance).data,status=status.HTTP_200_OK)
- else:
- return Response(serializer_detail.errors)
-
- else:
- return Response({'error':'答题记录不存在'})
- else:
- return Response(serializer.errors)
+ serializer.is_valid(raise_exception=True)
+ instance = serializer.save(consumer = request.user)
+ if 'questions' in request.data:
+ questions = []
+ for i in request.data['questions']:
+ question = {}
+ question['question'] = i['id']
+ question['examtest'] = instance.id
+ question['score'] = i['score']
+ if 'user_answer' in i:
+ question['user_answer'] = i['user_answer']
+ question['is_right'] = i['is_right']
+ questions.append(question)
+ serializer_detail = AnswerDetailCreateSerializer(data=questions, many=True)
+ serializer_detail.is_valid(raise_exception=True)
+ serializer_detail.save()
+ # 关联正式考试如有
+ if request.data.get('exam', None):
+ exam = Exam.objects.get(pk=request.data['exam'])
+ instance.exam = exam
+ instance.save()
+ # 自动发证
+ if exam.auto_issue and instance.is_pass:
+ issue(instance)
+ return Response(MoniTestSerializer(instance).data,status=status.HTTP_200_OK)
+ raise ParseError('答题记录不存在')
@action(methods=['get'], detail=False,
url_path='export', url_name='export_test', perms_map=[{'*':'export_test'}])
@@ -645,6 +639,7 @@ class PaperViewSet(PageOrNot, ModelViewSet):
instance = serializer.save()
if 'questions' in data:
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']:
question = {}
question['question'] = i['id']
@@ -669,6 +664,7 @@ class PaperViewSet(PageOrNot, ModelViewSet):
self.perform_update(serializer)
if 'questions' in data:
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']:
question = {}
question['question'] = i['id']
diff --git a/test_server/rbac/models.py b/test_server/rbac/models.py
index 92af2a8..a4bc604 100644
--- a/test_server/rbac/models.py
+++ b/test_server/rbac/models.py
@@ -32,14 +32,15 @@ class SoftDeletableManagerMixin(object):
"""
_queryset_class = SoftDeletableQuerySet
- def get_queryset(self):
+ def get_queryset(self, all=False):
"""
Return queryset limited to not deleted entries.
"""
kwargs = {'model': self.model, 'using': self._db}
if hasattr(self, '_hints'):
kwargs['hints'] = self._hints
-
+ if all:
+ return self._queryset_class(**kwargs)
return self._queryset_class(**kwargs).filter(is_delete=False)
diff --git a/test_server/utils/response.py b/test_server/utils/response.py
index 8bcf799..49d6483 100644
--- a/test_server/utils/response.py
+++ b/test_server/utils/response.py
@@ -50,6 +50,8 @@ class FitJSONRenderer(JSONRenderer):
data = data[list(data.keys())[0]]
if isinstance(data, list):
data = data[0]
+ if not isinstance(data, str):
+ data = '请求错误'
response_body.msg = data
elif data and 'error' in data and data['error']:# 自传异常,key为error
response_body.code = data.get("code",400)