CloudTest.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # -*- coding: utf-8 -*-
  2. """
  3. @Time : 2020/12/16 8:44
  4. @Auth : Locky
  5. @File :CloudTest.py
  6. @IDE :PyCharm
  7. """
  8. from django.views.generic.base import View
  9. from Model.models import Device_Info
  10. from Object.ResponseObject import ResponseObject
  11. from Object.TokenObject import TokenObject
  12. class cloudTestView(View):
  13. def get(self, request, *args, **kwargs):
  14. request.encoding = 'utf-8'
  15. operation = kwargs.get('operation')
  16. return self.validation(request.GET, request, operation)
  17. def post(self, request, *args, **kwargs):
  18. request.encoding = 'utf-8'
  19. operation = kwargs.get('operation')
  20. return self.validation(request.POST, request, operation)
  21. def validation(self, request_dict, request, operation):
  22. response = ResponseObject()
  23. # if operation == 'deviceTransfer':
  24. # return self.deviceTransfer(request_dict, response)
  25. if operation is None:
  26. return response.json(444, 'error path')
  27. else:
  28. token = request_dict.get('token', None)
  29. # 设备主键uid
  30. tko = TokenObject(token)
  31. response.lang = tko.lang
  32. if tko.code != 0:
  33. return response.json(tko.code)
  34. userID = tko.userID
  35. if operation == 'deviceTransfer':
  36. return self.deviceTransfer(request_dict, response)
  37. def deviceTransfer(self, request_dict, response):
  38. # 设备转移
  39. userID = request_dict.get("userID", None)
  40. oldUID = request_dict.get('oldUID', None)
  41. newUID = request_dict.get('newUID', None)
  42. # 查询设备是否存在且支持云存功能
  43. oldUIDdevice_qs = Device_Info.objects.filter(userID_id=userID, UID=oldUID, isVod=1, isExist=1)
  44. newUIDdevice_qs = Device_Info.objects.filter(userID_id=userID, UID=newUID, isVod=1, isExist=1)
  45. try:
  46. if oldUIDdevice_qs[0] and newUIDdevice_qs[0]:
  47. # 更新UID
  48. oldUIDdevice_qs.update(UID=newUID)
  49. except Exception as e:
  50. print('更新失败')
  51. return response.json(500, repr(e))
  52. else:
  53. return response.json(0)