fix: exam/view 考试试题删除
This commit is contained in:
parent
2f067ff199
commit
24552d5b28
|
@ -92,7 +92,8 @@
|
|||
<div slot="header" style="display: flex;">
|
||||
<span>第{{ index+1 }}题</span>
|
||||
<el-link style="margin-left: auto; margin-right: 8px" type="primary" @click="handleEdit(item, index)" icon="el-icon-edit"></el-link>
|
||||
<el-link style="margin-right: 4px" type="danger" @click="handleDelete(index)" icon="el-icon-delete"></el-link>
|
||||
<el-link style="margin-right: 4px" type="danger" @click="handleDelete(index)" icon="el-icon-remove"></el-link>
|
||||
<el-link style="margin-right: 4px" type="danger" @click="handleDelete2(item, index)" icon="el-icon-delete"></el-link>
|
||||
</div>
|
||||
<div style="font-weight: bold;">
|
||||
<el-tag>{{item.type}}</el-tag>
|
||||
|
@ -113,7 +114,7 @@
|
|||
|
||||
</template>
|
||||
<script>
|
||||
import { getQuestioncatList, createPaper, UploadPaper } from "@/api/exam";
|
||||
import { getQuestioncatList, createPaper, UploadPaper, deleteQuestion } from "@/api/exam";
|
||||
import Questionchoose from "@/views/exam/questionChoose";
|
||||
import { upUrl, upHeaders } from "@/api/file";
|
||||
import draggable from 'vuedraggable';
|
||||
|
@ -256,6 +257,17 @@
|
|||
handleDelete(val) {
|
||||
this.questions.splice(val, 1);
|
||||
},
|
||||
handleDelete2(item, val){
|
||||
deleteQuestion(item.id).then(res=>{
|
||||
if (res.code == 200) {
|
||||
this.questions.splice(val, 1);
|
||||
this.$message({
|
||||
type: "success",
|
||||
message: "删除成功!"
|
||||
});
|
||||
}
|
||||
})
|
||||
},
|
||||
calScore() {
|
||||
let danxuan_count = 0,
|
||||
duoxuan_count = 0,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from django.db import models
|
||||
from apps.system.models import CommonAModel, CommonBModel
|
||||
from apps.system.models import CommonAModel, CommonBModel, CommonBDModel
|
||||
from django.contrib.postgres.fields import JSONField
|
||||
from utils.model import BaseModel
|
||||
from apps.edu.models import Course
|
||||
|
@ -99,7 +99,7 @@ class Exam(CommonAModel):
|
|||
return self.name
|
||||
|
||||
|
||||
class ExamRecord(CommonBModel):
|
||||
class ExamRecord(CommonBDModel):
|
||||
'''
|
||||
考试记录表
|
||||
'''
|
||||
|
|
|
@ -11,7 +11,7 @@ from rest_framework.permissions import IsAuthenticated
|
|||
from rest_framework.exceptions import ParseError
|
||||
from openpyxl import Workbook, load_workbook
|
||||
from django.conf import settings
|
||||
from apps.exam.models import Paper, Exam, ExamRecord, AnswerDetail
|
||||
from apps.exam.models import Paper, Exam, ExamRecord, AnswerDetail, PaperQuestion
|
||||
from django.utils import timezone
|
||||
from django.db import transaction
|
||||
from rest_framework.serializers import Serializer
|
||||
|
@ -68,6 +68,18 @@ class QuestionViewSet(CreateUpdateCustomMixin, ModelViewSet):
|
|||
filterset_fields = ['level', 'type', 'year', 'questioncat']
|
||||
search_fields = ['name', 'options', 'resolution']
|
||||
|
||||
def destroy(self, request, *args, **kwargs):
|
||||
"""
|
||||
删除题目
|
||||
"""
|
||||
instance = self.get_object()
|
||||
id = instance.id
|
||||
# 删除前进行校验,如果存在考试中不允许删除。
|
||||
paperquestion = PaperQuestion.objects.filter(question_id=id).exists()
|
||||
if paperquestion:
|
||||
return Response(('此试题存在考试中不允许删除'),status=403)
|
||||
instance.delete(soft=False)
|
||||
return Response(status=204)
|
||||
|
||||
@action(methods=['post'], detail=False, url_name='enable_question', perms_map={'post': 'question'}, serializer_class=Serializer)
|
||||
def enable(self, request):
|
||||
|
@ -88,9 +100,13 @@ class QuestionViewSet(CreateUpdateCustomMixin, ModelViewSet):
|
|||
"""
|
||||
ids = request.data.get('ids', [])
|
||||
if request.user.is_superuser:
|
||||
# 删除前进行校验,如果存在考试中不允许删除。
|
||||
paperquestion = PaperQuestion.objects.filter(question__id__in=ids).exists()
|
||||
if paperquestion:
|
||||
return Response(('此试题存在考试中不允许删除'),status=403)
|
||||
Question.objects.filter(id__in=ids).update(is_deleted=True)
|
||||
return Response()
|
||||
return Response({'error':'权限不足'})
|
||||
return Response({'msg':'权限不足'},status=401)
|
||||
|
||||
@action(methods=['get'], detail=False, perms_map={'get':'export_question'})
|
||||
def export(self, request):
|
||||
|
|
Loading…
Reference in New Issue