|
@@ -5,9 +5,10 @@ from django.utils.decorators import method_decorator
|
|
|
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
from django.views.generic import TemplateView
|
|
|
-from Model.models import CountryModel, RegionModel, P2PIpModel, DeviceDomainModel, DeviceDomainRegionModel
|
|
|
+from Model.models import CountryModel, RegionModel, P2PIpModel, DeviceDomainModel, DeviceDomainRegionModel, IPAddr
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Service.CommonService import CommonService
|
|
|
+from Object.IPWeatherObject import IPQuery
|
|
|
|
|
|
|
|
|
#确认设备所在地区
|
|
@@ -20,14 +21,19 @@ class ConfirmRegion(TemplateView):
|
|
|
response = ResponseObject()
|
|
|
request.encoding = 'utf-8'
|
|
|
try:
|
|
|
- ip = CommonService.get_ip_address(request)
|
|
|
+ ip = request.GET.get('ip', None)
|
|
|
device_domain_data = {'ip': ip}
|
|
|
- ipInfo = CommonService.getIpIpInfo(ip, 'CN')
|
|
|
+ ip_addr_qs = IPAddr.objects.filter(ip=ip).values("country_code")
|
|
|
+ if ip_addr_qs.exists():
|
|
|
+ country_code = ip_addr_qs[0]['country_code']
|
|
|
+ else:
|
|
|
+ ip_qs = IPQuery(ip)
|
|
|
+ country_code = ip_qs.country_id
|
|
|
logger = logging.getLogger('info')
|
|
|
- logger.info('设备获取域名---ip:{},country_code:{}'.format(ip, ipInfo['country_code']))
|
|
|
- if ipInfo['country_code']:
|
|
|
- device_domain_data['country_name'] = ipInfo['country_code']
|
|
|
- device_request_url = CountryModel.objects.filter(country_code=ipInfo['country_code']).values("region__api")
|
|
|
+ logger.info('设备获取域名---ip:{},country_code:{}'.format(ip, country_code))
|
|
|
+ if country_code:
|
|
|
+ device_domain_data['country_name'] = country_code
|
|
|
+ device_request_url = CountryModel.objects.filter(country_code=country_code).values("region__api")
|
|
|
if device_request_url.exists():
|
|
|
api = device_request_url[0]['region__api']
|
|
|
device_domain_data['api'] = api
|