# -*- coding: utf-8 -*- """ @Time : 2020/12/16 8:44 @Auth : Locky @File :CloudTest.py @IDE :PyCharm """ from django.views.generic.base import View from Model.models import Device_Info from Object.ResponseObject import ResponseObject from Object.TokenObject import TokenObject class cloudTestView(View): def get(self, request, *args, **kwargs): request.encoding = 'utf-8' operation = kwargs.get('operation') return self.validation(request.GET, request, operation) def post(self, request, *args, **kwargs): request.encoding = 'utf-8' operation = kwargs.get('operation') return self.validation(request.POST, request, operation) def validation(self, request_dict, request, operation): response = ResponseObject() if operation is None: return response.json(444, 'error path') else: token = request_dict.get('token', None) # 设备主键uid tko = TokenObject(token) response.lang = tko.lang if tko.code != 0: return response.json(tko.code) userID = tko.userID if operation == 'deviceTransfer': return self.deviceTransfer(request_dict, response) def deviceTransfer(self, request_dict, response): # 设备转移 oldUserID = request_dict.get("oldUserID", None) newUserID = request_dict.get("newUserID", None) uid = request_dict.get('uid', None) # 查询设备是否存在且支持云存功能 oldUserID_device_qs = Device_Info.objects.filter(userID_id=oldUserID, UID=uid, isVod=1, isExist=1) newUserID_device_qs = Device_Info.objects.filter(userID_id=newUserID, isVod=1, isExist=1) try: if oldUserID_device_qs[0] and newUserID_device_qs[0]: # 更新userID_id oldUserID_device_qs.update(userID_id=newUserID) except Exception as e: # print('更新失败') return response.json(500, repr(e)) else: return response.json(0)