|
@@ -28,69 +28,47 @@ class searchUserView(View):
|
|
return self.searchUser(fieldDict, args, kwargs)
|
|
return self.searchUser(fieldDict, args, kwargs)
|
|
|
|
|
|
def searchUserSQL(self, fieldDict, response, *args, **kwargs):
|
|
def searchUserSQL(self, fieldDict, response, *args, **kwargs):
|
|
- exact = fieldDict.get('exact', True)
|
|
|
|
- if exact == '0' or exact == 'False':
|
|
|
|
- exact = False
|
|
|
|
|
|
+ if 'username' in fieldDict.keys():
|
|
|
|
+ username = fieldDict.get('username', None)
|
|
|
|
+ User = Device_User.objects.filter(
|
|
|
|
+ Q(username=username) | Q(phone=username) | Q(userEmail=username)).order_by('-data_joined')
|
|
|
|
+ elif 'userEmail' in fieldDict.keys():
|
|
|
|
+ email = fieldDict.get('userEmail', None)
|
|
|
|
+ User = Device_User.objects.filter(Q(userEmail=email) | Q(username=email)).order_by('-data_joined')
|
|
|
|
+ elif 'userID' in fieldDict.keys():
|
|
|
|
+ userID = fieldDict.get('userID', None)
|
|
|
|
+ User = Device_User.objects.filter(userID=userID).order_by('-data_joined')
|
|
else:
|
|
else:
|
|
- exact = True
|
|
|
|
-
|
|
|
|
- if 'exact' in fieldDict.keys():
|
|
|
|
- fieldDict.pop('exact')
|
|
|
|
- try:
|
|
|
|
- if exact == 'True' or exact == 1:
|
|
|
|
- User = Device_User.objects.filter(**fieldDict).order_by('-data_joined')
|
|
|
|
- # elif exact == 'False' or exact == 0:
|
|
|
|
- else:
|
|
|
|
- if 'username' in fieldDict.keys():
|
|
|
|
- username = fieldDict.get('username',None)
|
|
|
|
- User = Device_User.objects.filter(Q(username=username)|Q(phone=username)|Q(userEmail=username)).order_by('-data_joined')
|
|
|
|
- elif 'userEmail' in fieldDict.keys():
|
|
|
|
- email = fieldDict.get('userEmail',None)
|
|
|
|
- User = Device_User.objects.filter(Q(userEmail=email)|Q(username=email)).order_by('-data_joined')
|
|
|
|
- elif 'userID' in fieldDict.keys():
|
|
|
|
- userID = fieldDict.get('userID',None)
|
|
|
|
- User = Device_User.objects.filter(userID=userID).order_by('-data_joined')
|
|
|
|
- else:
|
|
|
|
- User = Device_User.objects.filter(**fieldDict).order_by('-data_joined')
|
|
|
|
- # else:
|
|
|
|
- # User = Device_User.objects.filter(**fieldDict).order_by('-data_joined')
|
|
|
|
-
|
|
|
|
- except FieldError:
|
|
|
|
- return response.json(502)
|
|
|
|
- except Exception as e:
|
|
|
|
- errorInfo = traceback.format_exc()
|
|
|
|
- print('查询数据库错误: %s' % errorInfo)
|
|
|
|
- return response.json(500, {'details': repr(e)})
|
|
|
|
- else:
|
|
|
|
- if User:
|
|
|
|
- ddUser = User[0].device_info_set.all()
|
|
|
|
- sqlJSON = serializers.serialize('json', User)
|
|
|
|
- sqlList = json.loads(sqlJSON)
|
|
|
|
- if ddUser:
|
|
|
|
- sqlJSON1 = serializers.serialize('json', ddUser)
|
|
|
|
- sqlList1 = json.loads(sqlJSON1)
|
|
|
|
|
|
+ User = Device_User.objects.filter(**fieldDict).order_by('-data_joined')
|
|
|
|
+ if User.exists():
|
|
|
|
+ ddUser = User[0].device_info_set.all()
|
|
|
|
+ sqlJSON = serializers.serialize('json', User)
|
|
|
|
+ sqlList = json.loads(sqlJSON)
|
|
|
|
+ if ddUser:
|
|
|
|
+ sqlJSON1 = serializers.serialize('json', ddUser)
|
|
|
|
+ sqlList1 = json.loads(sqlJSON1)
|
|
|
|
+ device_Info_dict = {}
|
|
|
|
+ device_Info_list = []
|
|
|
|
+ for eachJson1 in sqlList1:
|
|
|
|
+ device_Info_dict['primaryUserID'] = eachJson1['fields']['primaryUserID']
|
|
|
|
+ device_Info_dict['Type'] = eachJson1['fields']['Type']
|
|
|
|
+ device_Info_dict['UID'] = eachJson1['fields']['UID']
|
|
|
|
+ device_Info_dict['pk'] = eachJson1['pk']
|
|
|
|
+ device_Info_dict['NickName'] = eachJson1['fields']['NickName']
|
|
|
|
+ device_Info_dict['View_Password'] = eachJson1['fields']['View_Password']
|
|
|
|
+ device_Info_dict['View_Account'] = eachJson1['fields']['View_Account']
|
|
|
|
+ device_Info_dict['Online'] = eachJson1['fields']['Online']
|
|
|
|
+ device_Info_dict['EventNotification'] = eachJson1['fields']['EventNotification']
|
|
|
|
+ device_Info_dict['ChannelIndex'] = eachJson1['fields']['ChannelIndex']
|
|
|
|
+ device_Info_dict['EventNotification'] = eachJson1['fields']['EventNotification']
|
|
|
|
+ device_Info_dict['NotificationMode'] = eachJson1['fields']['NotificationMode']
|
|
|
|
+ device_Info_list.append(device_Info_dict)
|
|
device_Info_dict = {}
|
|
device_Info_dict = {}
|
|
- device_Info_list = []
|
|
|
|
- for eachJson1 in sqlList1:
|
|
|
|
- device_Info_dict['primaryUserID'] = eachJson1['fields']['primaryUserID']
|
|
|
|
- device_Info_dict['Type'] = eachJson1['fields']['Type']
|
|
|
|
- device_Info_dict['UID'] = eachJson1['fields']['UID']
|
|
|
|
- device_Info_dict['pk'] = eachJson1['pk']
|
|
|
|
- device_Info_dict['NickName'] = eachJson1['fields']['NickName']
|
|
|
|
- device_Info_dict['View_Password'] = eachJson1['fields']['View_Password']
|
|
|
|
- device_Info_dict['View_Account'] = eachJson1['fields']['View_Account']
|
|
|
|
- device_Info_dict['Online'] = eachJson1['fields']['Online']
|
|
|
|
- device_Info_dict['EventNotification'] = eachJson1['fields']['EventNotification']
|
|
|
|
- device_Info_dict['ChannelIndex'] = eachJson1['fields']['ChannelIndex']
|
|
|
|
- device_Info_dict['EventNotification'] = eachJson1['fields']['EventNotification']
|
|
|
|
- device_Info_dict['NotificationMode'] = eachJson1['fields']['NotificationMode']
|
|
|
|
- device_Info_list.append(device_Info_dict)
|
|
|
|
- device_Info_dict = {}
|
|
|
|
- sqlList[0]['device_info'] = device_Info_list
|
|
|
|
- sqlDict = dict(zip(["datas"], [sqlList]))
|
|
|
|
- return response.json(0, sqlDict)
|
|
|
|
- else:
|
|
|
|
- return response.json(102)
|
|
|
|
|
|
+ sqlList[0]['device_info'] = device_Info_list
|
|
|
|
+ sqlDict = dict(zip(["datas"], [sqlList]))
|
|
|
|
+ return response.json(0, sqlDict)
|
|
|
|
+ else:
|
|
|
|
+ return response.json(102)
|
|
|
|
|
|
def searchUserPCSQL(self, fieldDict, response):
|
|
def searchUserPCSQL(self, fieldDict, response):
|
|
try:
|
|
try:
|