diff --git a/server/apps/supervision/views.py b/server/apps/supervision/views.py index ce54cea..0ad7418 100644 --- a/server/apps/supervision/views.py +++ b/server/apps/supervision/views.py @@ -99,28 +99,28 @@ class TaskViewSet(CreateUpdateCustomMixin, ModelViewSet): obj = self.get_object() depts = request.data['depts'] contents = request.data['contents'] - if obj.state in ['待发布', '执行中']: - return Response('任务状态错误', status=status.HTTP_400_BAD_REQUEST) - if depts and contents: - for m in depts: - m = Organization.objects.get(pk=m) - TaskDept.objects.get_or_create(task=obj, dept=m, defaults={'task':obj, 'dept':m}) - for n in contents: - n = Content.objects.get(pk=n) - if not Record.objects.filter(belong_dept=m, content=n, task=obj).exists(): - r = Record() - r.content = n - r.content_name = n.name - r.content_desc = n.desc - r.belong_dept = m - r.task = obj - r.end_date = obj.end_date - r.create_by = request.user - r.state = '待上报' - r.save() - obj.save() - return Response(status=status.HTTP_200_OK) - return Response('单位或清单不能为空', status=status.HTTP_400_BAD_REQUEST) + if obj.state in ['待发布', '执行中']: + if depts and contents: + for m in depts: + m = Organization.objects.get(pk=m) + TaskDept.objects.get_or_create(task=obj, dept=m, defaults={'task':obj, 'dept':m}) + for n in contents: + n = Content.objects.get(pk=n) + if not Record.objects.filter(belong_dept=m, content=n, task=obj).exists(): + r = Record() + r.content = n + r.content_name = n.name + r.content_desc = n.desc + r.belong_dept = m + r.task = obj + r.end_date = obj.end_date + r.create_by = request.user + r.state = '待上报' + r.save() + obj.save() + return Response(status=status.HTTP_200_OK) + return Response('单位或清单不能为空', status=status.HTTP_400_BAD_REQUEST) + return Response('任务状态错误', status=status.HTTP_400_BAD_REQUEST) @action(methods=['get'], detail=True, perms_map = {'get':'*'})