views.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 .models import Bar
  10. from utils.executeQuery import executeQuery
  11. from .utils import display
  12. # 查询员工信息
  13. class Salm(APIView):
  14. # 1,设置局部认证
  15. authentication_classes = (JSONWebTokenAuthentication, SessionAuthentication,)
  16. # authentication_classes = [SessionAuthentication, BasicAuthentication]
  17. # 2,设置局部权限
  18. permission_classes = (IsAuthenticated,)
  19. def get(self,request):
  20. sql = """select sal_no as value,cast(sal_no as varchar(20)) + '--' + name as label from salm"""
  21. result = executeQuery(sql)
  22. # print(result)
  23. return Response(result,status=status.HTTP_200_OK)
  24. # 查询制程信息
  25. class ZcNo(APIView):
  26. # 1,设置局部认证
  27. authentication_classes = (JSONWebTokenAuthentication, SessionAuthentication,)
  28. # authentication_classes = [SessionAuthentication, BasicAuthentication]
  29. # 2,设置局部权限
  30. permission_classes = (IsAuthenticated,)
  31. def get(self,request):
  32. # 获取用户等级
  33. is_superuser = request.user.is_superuser
  34. # 获取登录用户
  35. users = request.user
  36. print(users)
  37. sql = """select zc_no as value,cast(zc_no as varchar(20)) + '--' + name as label from zc_no"""
  38. if is_superuser==False:
  39. 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)
  40. result = executeQuery(sql)
  41. # print(result)
  42. return Response(result,status=status.HTTP_200_OK)
  43. # 查询菜单栏
  44. class Bars(APIView):
  45. # 1,设置局部认证
  46. authentication_classes = (JSONWebTokenAuthentication, SessionAuthentication,)
  47. # authentication_classes = [SessionAuthentication, BasicAuthentication]
  48. # 2,设置局部权限
  49. permission_classes = (IsAuthenticated,)
  50. def get(self,request):
  51. bar_list = Bar.objects.filter(partment_id=None)
  52. bar = display(bar_list)
  53. print(bar)
  54. data = {
  55. 'bar':bar
  56. }
  57. return Response(data,status=status.HTTP_200_OK)