From 9d625e76ac5be85924aa7b47741cc4ae92737510 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Sun, 12 Dec 2021 23:16:01 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=98=E7=9B=AE=E6=89=B9=E9=87=8F=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E4=BB=A5=E5=8F=8A=E6=90=9C=E7=B4=A2=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test_client/src/api/question.js | 7 +++++++ test_client/src/views/question/question.vue | 19 +++++++++++++++++- test_server/question/views.py | 22 +++++++++++++++++++-- 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/test_client/src/api/question.js b/test_client/src/api/question.js index 63d51f0..b526fe3 100644 --- a/test_client/src/api/question.js +++ b/test_client/src/api/question.js @@ -108,6 +108,13 @@ export function deleteQuestion(id) { method: 'delete', }) } +export function deleteQuestions(data) { + return request({ + url: `/question/question/deletes/`, + method: 'post', + data + }) +} export function importQuestion(data) { return request({ url: `/question/question/import/`, diff --git a/test_client/src/views/question/question.vue b/test_client/src/views/question/question.vue index 6d6049e..1c5c27f 100644 --- a/test_client/src/views/question/question.vue +++ b/test_client/src/views/question/question.vue @@ -70,6 +70,12 @@ Excel导入 导出Excel +批量删除 { + this.$message.success("成功"); + this.getList(); + }) + } else { + this.$message.warning("请先选择题目"); + } + }, exportQuestion() { const loading = this.$loading({ text:'正在准备..' diff --git a/test_server/question/views.py b/test_server/question/views.py index 738eb80..31a0314 100644 --- a/test_server/question/views.py +++ b/test_server/question/views.py @@ -6,13 +6,13 @@ from rest_framework import status from rest_framework.decorators import action, permission_classes from rest_framework.filters import OrderingFilter, SearchFilter from rest_framework.generics import GenericAPIView -from rest_framework.permissions import IsAuthenticated +from rest_framework.permissions import IsAdminUser, IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView from rest_framework.viewsets import ModelViewSet from rest_framework_jwt.authentication import JSONWebTokenAuthentication -from crm.models import PaySubject +from crm.models import Consumer, PaySubject from examtest.models import WorkScope from server import settings from utils.custom import CommonPagination @@ -116,6 +116,13 @@ class QuestionViewSet(ModelViewSet): ret['panduan'] = queryset.filter(type='判断').count() return Response(ret) + def get_queryset(self): + user = self.request.user + if isinstance(user, Consumer): + questioncats = user.workscope.questioncat.all() + self.queryset = self.queryset.filter(questioncat__in = questioncats) + return super().get_queryset() + @action(methods=['get'], detail=False, url_path='export', url_name='export_question', perms_map=[{'*':'export_question'}]) def export(self, request): @@ -143,6 +150,17 @@ class QuestionViewSet(ModelViewSet): i.save() return Response() + @action(methods=['post'], detail=False, perms_map=[{'*':'question_delete'}]) + def deletes(self, request): + """ + 批量删除 + """ + ids = request.data.get('ids', []) + if request.user.is_superuser: + Question.objects.filter(id__in=ids).update(is_delete=True) + return Response() + return Response({'error':'权限不足'}) + @action(methods=['post'], detail=False, url_name='enable_question', permission_classes=[IsAuthenticated]) def enable(self, request): ids = request.data.get('ids',None)