fix: exam/view.py 更改题库批量删除
This commit is contained in:
parent
5b785dfd79
commit
0286ba33cd
|
@ -256,10 +256,23 @@
|
||||||
this.questions.splice(val, 1);
|
this.questions.splice(val, 1);
|
||||||
},
|
},
|
||||||
handleDelete2(item, val){
|
handleDelete2(item, val){
|
||||||
|
this.$confirm("此操作将永久删除该题目, 是否继续?", "提示", {
|
||||||
deleteQuestion(item.id).then(res=>{
|
type: "warning"
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
this.delquestion(item.id, val);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
this.$message({
|
||||||
|
type: "info",
|
||||||
|
message: "已取消删除"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
delquestion(id, val){
|
||||||
|
deleteQuestion(id).then(res=>{
|
||||||
console.log(res)
|
console.log(res)
|
||||||
if (res.code ==204) {
|
if (res.code >=200) {
|
||||||
this.$message({
|
this.$message({
|
||||||
type: "success",
|
type: "success",
|
||||||
message: "删除成功!"
|
message: "删除成功!"
|
||||||
|
|
|
@ -500,12 +500,16 @@ export default {
|
||||||
type: "error",
|
type: "error",
|
||||||
})
|
})
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
await deleteUserExam(scope.row.id);
|
deleteUserExam(scope.row.id).then((res) => {
|
||||||
this.userList.splice(scope.row.index, 1);
|
console.log(res);
|
||||||
|
if (res.code >= 200) {
|
||||||
|
// this.userList.splice(scope.row.index, 1);
|
||||||
this.$message.success("成功");
|
this.$message.success("成功");
|
||||||
|
this.getList();
|
||||||
|
};
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
async confirm(form) {
|
async confirm(form) {
|
||||||
|
|
|
@ -99,12 +99,18 @@ class QuestionViewSet(CreateUpdateCustomMixin, ModelViewSet):
|
||||||
"""
|
"""
|
||||||
ids = request.data.get('ids', [])
|
ids = request.data.get('ids', [])
|
||||||
if request.user.is_superuser:
|
if request.user.is_superuser:
|
||||||
|
question_list= []
|
||||||
# 删除前进行校验,如果存在考试中不允许删除。
|
# 删除前进行校验,如果存在考试中不允许删除。
|
||||||
paperquestion = PaperQuestion.objects.filter(question__id__in=ids).exists()
|
for u in ids:
|
||||||
|
paperquestion = PaperQuestion.objects.filter(question_id=u)
|
||||||
if paperquestion:
|
if paperquestion:
|
||||||
return Response('此试题存在考试中不允许删除')
|
qobj = Question.objects.get(id=u)
|
||||||
Question.objects.filter(id__in=ids).update(is_deleted=True)
|
question_list.append(qobj.name)
|
||||||
return Response()
|
else:
|
||||||
|
Question.objects.filter(id=u).delete()
|
||||||
|
if question_list:
|
||||||
|
raise ParseError(f'{question_list}-------存在考试中不允许删除')
|
||||||
|
return Response(status=200)
|
||||||
return Response({'msg':'权限不足'},status=401)
|
return Response({'msg':'权限不足'},status=401)
|
||||||
|
|
||||||
@action(methods=['get'], detail=False, perms_map={'get':'export_question'})
|
@action(methods=['get'], detail=False, perms_map={'get':'export_question'})
|
||||||
|
@ -490,7 +496,7 @@ class ExamViewSet(CreateUpdateCustomMixin, ModelViewSet):
|
||||||
instance = self.get_object()
|
instance = self.get_object()
|
||||||
if ExamRecord.objects.filter(exam=instance).exists():
|
if ExamRecord.objects.filter(exam=instance).exists():
|
||||||
raise ParseError('存在考试记录,禁止删除')
|
raise ParseError('存在考试记录,禁止删除')
|
||||||
instance.delete(soft=False)
|
instance.delete()
|
||||||
return Response(status=204)
|
return Response(status=204)
|
||||||
|
|
||||||
@action(methods=['post'], detail=True, perms_map={'post': '*'}, serializer_class=Serializer, permission_classes = [IsAuthenticated])
|
@action(methods=['post'], detail=True, perms_map={'post': '*'}, serializer_class=Serializer, permission_classes = [IsAuthenticated])
|
||||||
|
@ -580,7 +586,7 @@ class ExamRecordViewSet(ListModelMixin, DestroyModelMixin, RetrieveModelMixin, G
|
||||||
return super().get_serializer_class()
|
return super().get_serializer_class()
|
||||||
|
|
||||||
def perform_destroy(self, instance): # 考试记录物理删除
|
def perform_destroy(self, instance): # 考试记录物理删除
|
||||||
instance.delete(soft=False)
|
instance.delete()
|
||||||
|
|
||||||
@action(methods=['post'], detail=False, perms_map={'post': '*'}, serializer_class=Serializer, permission_classes = [IsAuthenticated])
|
@action(methods=['post'], detail=False, perms_map={'post': '*'}, serializer_class=Serializer, permission_classes = [IsAuthenticated])
|
||||||
def clear(self, request, pk=None):
|
def clear(self, request, pk=None):
|
||||||
|
|
Loading…
Reference in New Issue