|
@@ -17,14 +17,15 @@ from pyipip import IPIPDatabase
|
|
|
|
|
|
from Ansjer.config import BASE_DIR, SERVER_DOMAIN_SSL, CONFIG_INFO, CONFIG_TEST, CONFIG_CN
|
|
|
from Controller.CheckUserData import RandomStr
|
|
|
-from Controller.DeviceConfirmRegion import Device_Region
|
|
|
-from Model.models import iotdeviceInfoModel, Device_Info
|
|
|
+from Model.models import iotdeviceInfoModel, Device_Info, CountryModel, RegionModel
|
|
|
|
|
|
|
|
|
class CommonService:
|
|
|
# 添加模糊搜索
|
|
|
@staticmethod
|
|
|
- def get_kwargs(data={}):
|
|
|
+ def get_kwargs(data=None):
|
|
|
+ if data is None:
|
|
|
+ data = {}
|
|
|
kwargs = {}
|
|
|
for (k, v) in data.items():
|
|
|
if v is not None and v != u'':
|
|
@@ -73,8 +74,10 @@ class CommonService:
|
|
|
return mb_size
|
|
|
|
|
|
@staticmethod
|
|
|
- def get_param_flag(data=[]):
|
|
|
+ def get_param_flag(data=None):
|
|
|
# print(data)
|
|
|
+ if data is None:
|
|
|
+ data = []
|
|
|
flag = True
|
|
|
for v in data:
|
|
|
if v is None:
|
|
@@ -602,9 +605,17 @@ GCqvlyw5dfxNA+EtxNE2wCW/LW7ENJlACgcfgPlBZtpLheWoZB/maw4=
|
|
|
@param request: 请求体
|
|
|
@return region_id: 地区id
|
|
|
"""
|
|
|
+ region_id = 3
|
|
|
if CONFIG_INFO == CONFIG_TEST or CONFIG_INFO == CONFIG_CN:
|
|
|
region_id = 1
|
|
|
else: # 国外配置暂时通过ip确认
|
|
|
ip = CommonService.get_ip_address(request)
|
|
|
- region_id = Device_Region().get_device_region(ip)
|
|
|
+ ipInfo = CommonService.getIpIpInfo(ip, 'CN')
|
|
|
+ if ipInfo['country_code']:
|
|
|
+ country_qs = CountryModel.objects.filter(country_code=ipInfo['country_code']).values('region__id')
|
|
|
+ if country_qs.exists():
|
|
|
+ region_id = country_qs[0]['region__id']
|
|
|
+ else: # 不存在默认返回美洲地区api
|
|
|
+ region_qs = RegionModel.objects.filter(continent_code='NA').values("id")
|
|
|
+ region_id = region_qs[0]['id']
|
|
|
return region_id
|