views.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from django.shortcuts import render
  2. # Create your views here.
  3. from rest_framework import status
  4. from rest_framework.authentication import SessionAuthentication
  5. from rest_framework.permissions import IsAuthenticated
  6. from rest_framework.response import Response
  7. from rest_framework.views import APIView
  8. from rest_framework_jwt.authentication import JSONWebTokenAuthentication
  9. from utils.executeQuery import executeQuery
  10. # 查询员工信息
  11. class Salm(APIView):
  12. # 1,设置局部认证
  13. authentication_classes = (JSONWebTokenAuthentication, SessionAuthentication,)
  14. # authentication_classes = [SessionAuthentication, BasicAuthentication]
  15. # 2,设置局部权限
  16. permission_classes = (IsAuthenticated,)
  17. def get(self,request):
  18. sql = """select sal_no as value,cast(sal_no as varchar(20)) + '--' + name as label from salm"""
  19. result = executeQuery(sql)
  20. # print(result)
  21. return Response(result,status=status.HTTP_200_OK)
  22. # 查询制程信息
  23. class ZcNo(APIView):
  24. # 1,设置局部认证
  25. authentication_classes = (JSONWebTokenAuthentication, SessionAuthentication,)
  26. # authentication_classes = [SessionAuthentication, BasicAuthentication]
  27. # 2,设置局部权限
  28. permission_classes = (IsAuthenticated,)
  29. def get(self,request):
  30. # 获取用户等级
  31. is_superuser = request.user.is_superuser
  32. # 获取登录用户
  33. users = request.user
  34. print(users)
  35. sql = """select zc_no as value,cast(zc_no as varchar(20)) + '--' + name as label from zc_no"""
  36. if is_superuser==False:
  37. sql = """select zc_no as value,cast(zc_no as varchar(20)) + '--' + name as label from zc_no where yg_no like '%%{0}%%'""".format(users)
  38. result = executeQuery(sql)
  39. # print(result)
  40. return Response(result,status=status.HTTP_200_OK)