1
|
# _*_ coding: utf-8 _*_
|
1
|
# _*_ coding: utf-8 _*_
|
2
|
# @Time : 2020/10/7 10:40
|
2
|
# @Time : 2020/10/7 10:40
|
3
|
# @Author vanwhebin
|
3
|
# @Author vanwhebin
|
|
|
4
|
+import re
|
4
|
from rest_framework.generics import CreateAPIView, RetrieveAPIView, UpdateAPIView, ListAPIView
|
5
|
from rest_framework.generics import CreateAPIView, RetrieveAPIView, UpdateAPIView, ListAPIView
|
5
|
from rest_framework.permissions import IsAuthenticated, IsAdminUser
|
6
|
from rest_framework.permissions import IsAuthenticated, IsAdminUser
|
6
|
from rest_framework.exceptions import ValidationError
|
7
|
from rest_framework.exceptions import ValidationError
|
7
|
-from django.urls import reverse
|
8
|
+from rest_framework.views import APIView
|
8
|
from rest_framework.response import Response
|
9
|
from rest_framework.response import Response
|
|
|
10
|
+from django.contrib.auth.decorators import login_required
|
|
|
11
|
+from django.views.decorators.http import require_http_methods
|
9
|
|
12
|
|
10
|
from .serializers import ProjectSerializer
|
13
|
from .serializers import ProjectSerializer
|
|
|
14
|
+from usercenter.models import User
|
11
|
from .models import Auditor, Project, Result
|
15
|
from .models import Auditor, Project, Result
|
12
|
from utils.helpers import WxPushHelper
|
16
|
from utils.helpers import WxPushHelper
|
13
|
from utils.pagination import MyPageNumberPagination
|
17
|
from utils.pagination import MyPageNumberPagination
|
14
|
from utils.util import response
|
18
|
from utils.util import response
|
|
|
19
|
+from wxProject.settings import FRONT_URL
|
|
|
20
|
+
|
|
|
21
|
+AUDITORS = (
|
|
|
22
|
+ (2, '邓望明'),
|
|
|
23
|
+ (3, '杜波')
|
|
|
24
|
+)
|
15
|
|
25
|
|
16
|
|
26
|
|
17
|
class CreateProject(CreateAPIView):
|
27
|
class CreateProject(CreateAPIView):
|
|
@@ -23,13 +33,15 @@ class CreateProject(CreateAPIView): |
|
@@ -23,13 +33,15 @@ class CreateProject(CreateAPIView): |
23
|
wx_client = WxPushHelper()
|
33
|
wx_client = WxPushHelper()
|
24
|
serializer = ProjectSerializer(data=request.data)
|
34
|
serializer = ProjectSerializer(data=request.data)
|
25
|
if not serializer.is_valid():
|
35
|
if not serializer.is_valid():
|
26
|
- raise ValidationError
|
36
|
+ raise ValidationError(serializer.errors)
|
27
|
else:
|
37
|
else:
|
28
|
serializer.save(creator=request.user, auditor=Auditor.objects.order_by('-order').all())
|
38
|
serializer.save(creator=request.user, auditor=Auditor.objects.order_by('-order').all())
|
29
|
# 企业微信推送
|
39
|
# 企业微信推送
|
30
|
obj_dict = serializer.data
|
40
|
obj_dict = serializer.data
|
31
|
- wx_client.push_card(request.user.wx_token,
|
|
|
32
|
- reverse("project:retrieve_project", kwargs={"pk": obj_dict['id']}), u"流程创建成功")
|
41
|
+ url = re.sub("PK", obj_dict['id'], FRONT_URL['flow_detail'])
|
|
|
42
|
+ first_auditor = User.objects.filter(pk=AUDITORS[0][0]).first()
|
|
|
43
|
+ wx_client.push_card(first_auditor.wx_token, url, f"{request.user.username}提交了一个产品立项申请")
|
|
|
44
|
+ wx_client.push_card(request.user.wx_token, url, u"流程创建成功")
|
33
|
return response(obj_dict)
|
45
|
return response(obj_dict)
|
34
|
|
46
|
|
35
|
|
47
|
|
|
@@ -38,7 +50,9 @@ class ProjectDetail(RetrieveAPIView): |
|
@@ -38,7 +50,9 @@ class ProjectDetail(RetrieveAPIView): |
38
|
serializer_class = ProjectSerializer
|
50
|
serializer_class = ProjectSerializer
|
39
|
permission_classes = (IsAuthenticated,)
|
51
|
permission_classes = (IsAuthenticated,)
|
40
|
|
52
|
|
41
|
- # def get_object(self):
|
53
|
+ def get(self, request, *args, **kwargs):
|
|
|
54
|
+ obj = self.get_object()
|
|
|
55
|
+ return response(ProjectSerializer(obj).data)
|
42
|
|
56
|
|
43
|
|
57
|
|
44
|
class AuditProject(UpdateAPIView):
|
58
|
class AuditProject(UpdateAPIView):
|
|
@@ -81,6 +95,7 @@ class AuditProject(UpdateAPIView): |
|
@@ -81,6 +95,7 @@ class AuditProject(UpdateAPIView): |
81
|
|
95
|
|
82
|
wx_client = WxPushHelper()
|
96
|
wx_client = WxPushHelper()
|
83
|
full_audit_done = self._check_audit(obj)
|
97
|
full_audit_done = self._check_audit(obj)
|
|
|
98
|
+ url = re.sub("PK", obj.id, FRONT_URL['flow_detail'])
|
84
|
desc = "产品立项流程所有审批已完成" if full_audit_done else f"{request.user.username}已审批完成"
|
99
|
desc = "产品立项流程所有审批已完成" if full_audit_done else f"{request.user.username}已审批完成"
|
85
|
if full_audit_done:
|
100
|
if full_audit_done:
|
86
|
obj.is_done = True
|
101
|
obj.is_done = True
|
|
@@ -89,20 +104,45 @@ class AuditProject(UpdateAPIView): |
|
@@ -89,20 +104,45 @@ class AuditProject(UpdateAPIView): |
89
|
if not accept_param:
|
104
|
if not accept_param:
|
90
|
obj.is_done = True
|
105
|
obj.is_done = True
|
91
|
obj.is_pass = False
|
106
|
obj.is_pass = False
|
|
|
107
|
+ else:
|
|
|
108
|
+ second_auditor = User.objects.filter(pk=AUDITORS[1][0]).first()
|
|
|
109
|
+ wx_client.push_card(second_auditor.wx_token, url, f"{request.user.username}提交了一个产品立项申请")
|
92
|
obj.save()
|
110
|
obj.save()
|
93
|
- wx_client.push_card(obj.creator.wx_token, reverse("project:retrieve_project", kwargs={"pk": obj.id}), desc)
|
111
|
+ wx_client.push_card(obj.creator.wx_token, url, desc)
|
94
|
|
112
|
|
95
|
return response(ProjectSerializer(obj).data)
|
113
|
return response(ProjectSerializer(obj).data)
|
96
|
|
114
|
|
97
|
|
115
|
|
98
|
class AuditProjectsList(ListAPIView):
|
116
|
class AuditProjectsList(ListAPIView):
|
|
|
117
|
+ queryset = Project.objects.all()
|
99
|
serializer_class = ProjectSerializer
|
118
|
serializer_class = ProjectSerializer
|
100
|
pagination_class = MyPageNumberPagination
|
119
|
pagination_class = MyPageNumberPagination
|
101
|
permission_classes = (IsAuthenticated, IsAdminUser)
|
120
|
permission_classes = (IsAuthenticated, IsAdminUser)
|
102
|
|
121
|
|
103
|
- def get_queryset(self, **kwargs):
|
|
|
104
|
- return Project.objects.filter(auditor__user_id=kwargs['user'].id)
|
122
|
+ def get_queryset(self):
|
|
|
123
|
+ # auditor = Auditor.objects.get(user=self.request.user)
|
|
|
124
|
+ # sql = Project.objects.filter(
|
|
|
125
|
+ # auditor__user_id=self.request.user.id,
|
|
|
126
|
+ # auditor__result_auditor__exact=auditor) \
|
|
|
127
|
+ # .order_by('-is_done')
|
|
|
128
|
+ data = Project.objects.filter(auditor__user_id=self.request.user.id).order_by('-is_done')
|
|
|
129
|
+ for item in data:
|
|
|
130
|
+ result = item.result_project.filter(auditor__user_id=self.request.user.id).values('is_accept').first()
|
|
|
131
|
+ item.result = result['is_accept'] if result else False
|
|
|
132
|
+ # print(data.query)
|
|
|
133
|
+ return data
|
|
|
134
|
+#
|
|
|
135
|
+# def get(self, request, *args, **kwargs):
|
|
|
136
|
+# qs = self.get_queryset(user=request.user, **kwargs)
|
|
|
137
|
+# return response(ProjectSerializer(qs, many=True).data)
|
|
|
138
|
+
|
|
|
139
|
+
|
|
|
140
|
+class CheckAuth(APIView):
|
|
|
141
|
+ """ 检查是否有权限进行审批 """
|
|
|
142
|
+ allowed_methods = ('GET',)
|
|
|
143
|
+ permission_classes = (IsAuthenticated, IsAdminUser)
|
105
|
|
144
|
|
106
|
- def get(self, request, *args, **kwargs):
|
|
|
107
|
- qs = self.get_queryset(user=request.user)
|
|
|
108
|
- return response(ProjectSerializer(qs, many=True).data) |
145
|
+ @staticmethod
|
|
|
146
|
+ def get(request, *args, **kwargs):
|
|
|
147
|
+ project_auditor = Project.objects.filter(pk=kwargs['pk'], auditor__user_id=request.user.id)
|
|
|
148
|
+ return response(True) if project_auditor else response(False) |