|
@@ -0,0 +1,82 @@
|
|
|
+from django.shortcuts import render
|
|
|
+
|
|
|
+# Create your views here.
|
|
|
+from rest_framework import status
|
|
|
+from rest_framework.views import APIView
|
|
|
+from rest_framework.viewsets import ModelViewSet
|
|
|
+
|
|
|
+from relation.models import *
|
|
|
+from relation.serializer import *
|
|
|
+from rest_framework.response import Response
|
|
|
+
|
|
|
+class DaptViews(APIView):
|
|
|
+ def get(self, request):
|
|
|
+ parent_id = request.GET.get('parent_id')
|
|
|
+ daptSet = Dapt.objects.filter(parent_id = parent_id).values()
|
|
|
+ return Response(data=daptSet, status=status.HTTP_200_OK)
|
|
|
+
|
|
|
+ def post(self, request):
|
|
|
+ dapt = Dapt()
|
|
|
+ data = request.data
|
|
|
+ dapt.setObject(data)
|
|
|
+ dapt.save()
|
|
|
+ return Response(data=dapt.id, status=status.HTTP_200_OK)
|
|
|
+
|
|
|
+ def delete(self, request):
|
|
|
+ id = request.data['id']
|
|
|
+ Dapt.objects.filter(id = id).delete()
|
|
|
+ return Response(data=True, status=status.HTTP_200_OK)
|
|
|
+
|
|
|
+class PostViews(ModelViewSet):
|
|
|
+ queryset = Post.objects.all()
|
|
|
+ serializer_class = PostSerializer
|
|
|
+
|
|
|
+class UserViews(APIView):
|
|
|
+ def post(self, request):
|
|
|
+ data = request.data
|
|
|
+ user = User(last_name = data['last_name'], id=data['id'])
|
|
|
+ user.save()
|
|
|
+ return Response(data=True, status=status.HTTP_200_OK)
|
|
|
+ def get(self, request):
|
|
|
+ user = User.objects.values()
|
|
|
+ return Response(data=user, status=status.HTTP_200_OK)
|
|
|
+
|
|
|
+# class DaptPostViews(APIView):
|
|
|
+# def get(self, request):
|
|
|
+# get = request.GET
|
|
|
+# return Response(status=status.HTTP_200_OK)
|
|
|
+#部门人员
|
|
|
+class DaptUserViews(APIView):
|
|
|
+ def get(self, request):
|
|
|
+ daptId = request.GET.get('dapt_id')
|
|
|
+ userId = request.GET.get('user_id')
|
|
|
+ if daptId != None:
|
|
|
+ daptUserList = list(DaptUser.objects.filter(dapt_id=daptId))
|
|
|
+ userList = list()
|
|
|
+ for daptUser in daptUserList:
|
|
|
+ userList.append(daptUser.user)
|
|
|
+ data = UserSerializer(userList, many=True)
|
|
|
+ elif userId != None:
|
|
|
+ daptUserList = list(DaptUser.objects.filter(user_id=userId))
|
|
|
+ daptList = list()
|
|
|
+ for daptUser in daptUserList:
|
|
|
+ daptList.append(daptUser.dapt)
|
|
|
+ data = DaptSerializer(daptList, many=True)
|
|
|
+ return Response(data=data.data, status=status.HTTP_200_OK)
|
|
|
+
|
|
|
+ def post(self, reques):
|
|
|
+ data = reques.data
|
|
|
+ daptUser = DaptUser()
|
|
|
+ daptUser.setObject(data)
|
|
|
+ daptUser.save()
|
|
|
+ return Response(data=True, status=status.HTTP_200_OK)
|
|
|
+
|
|
|
+ def delete(self, reques):
|
|
|
+ userId = reques.data['user_id']
|
|
|
+ daptId = reques.data['dapt_id']
|
|
|
+ DaptUser.objects.get(user_id = userId, dapt_id=daptId).delete()
|
|
|
+ return Response(data=True, status=status.HTTP_200_OK)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|