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