当前位置: 首页>>代码示例>>Python>>正文


Python GeoIP.city方法代码示例

本文整理汇总了Python中django.contrib.gis.utils.GeoIP.city方法的典型用法代码示例。如果您正苦于以下问题:Python GeoIP.city方法的具体用法?Python GeoIP.city怎么用?Python GeoIP.city使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.contrib.gis.utils.GeoIP的用法示例。


在下文中一共展示了GeoIP.city方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_geoIP

# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import city [as 别名]
def get_geoIP(request):
    # marseille = Point(5.3697800, 43.2964820)
    clermont = Point(3.0870250, 45.7772220)
    ip = request.META.get('REMOTE_ADDR', None)

    g = GeoIP(path=settings.PROJECT_PATH + '/config/GEO/')

    if ip and g.city(ip):
        return (Point(g.city(ip)['longitude'], g.city(ip)['latitude']), 
               g.city(ip)['city'])
    else:
        return getattr(settings, 'DEFAULT_MAIN_CITY', (clermont, u'Clermont-Fd'))  # default city
开发者ID:credis,项目名称:pes,代码行数:14,代码来源:utils.py

示例2: location

# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import city [as 别名]
def location(request):
    """
    Location selection of the user profile
    """
    profile, created = Profile.objects.get_or_create(user=request.user)
    geoip = hasattr(settings, "GEOIP_PATH")
    if geoip and request.method == "GET" and request.GET.get('ip') == "1":
        from django.contrib.gis.utils import GeoIP
        g = GeoIP()
        c = g.city(request.META.get("REMOTE_ADDR"))
        if c and c.get("latitude") and c.get("longitude"):
            profile.latitude = "%.6f" % c.get("latitude")
            profile.longitude = "%.6f" % c.get("longitude")
            profile.country = c.get("country_code")
            profile.location = unicode(c.get("city"), "latin1")

    if request.method == "POST":
        form = LocationForm(request.POST, instance=profile)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse("profile_edit_location_done"))
    else:
        form = LocationForm(instance=profile)

    template = "member/profile/location.html"
    data = { 'section': 'location', 'GOOGLE_MAPS_API_KEY': GOOGLE_MAPS_API_KEY,
             'form': form, 'geoip': geoip }
    return render_to_response(template, data, context_instance=RequestContext(request))
开发者ID:woshicainiao,项目名称:ddtcms,代码行数:30,代码来源:views.py

示例3: test04_city

# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import city [as 别名]
    def test04_city(self):
        "Testing GeoIP city querying methods."
        g = GeoIP(country="<foo>")

        addr = "130.80.29.3"
        fqdn = "chron.com"
        for query in (fqdn, addr):
            # Country queries should still work.
            for func in (g.country_code, g.country_code_by_addr, g.country_code_by_name):
                self.assertEqual("US", func(query))
            for func in (g.country_name, g.country_name_by_addr, g.country_name_by_name):
                self.assertEqual("United States", func(query))
            self.assertEqual({"country_code": "US", "country_name": "United States"}, g.country(query))

            # City information dictionary.
            d = g.city(query)
            self.assertEqual("USA", d["country_code3"])
            self.assertEqual("Houston", d["city"])
            self.assertEqual("TX", d["region"])
            self.assertEqual(713, d["area_code"])
            geom = g.geos(query)
            self.failIf(not isinstance(geom, GEOSGeometry))
            lon, lat = (-95.4152, 29.7755)
            lat_lon = g.lat_lon(query)
            lat_lon = (lat_lon[1], lat_lon[0])
            for tup in (geom.tuple, g.coords(query), g.lon_lat(query), lat_lon):
                self.assertAlmostEqual(lon, tup[0], 4)
                self.assertAlmostEqual(lat, tup[1], 4)
开发者ID:greggian,项目名称:TapdIn,代码行数:30,代码来源:test_geoip.py

示例4: location

# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import city [as 别名]
def location(request):
    """
    Location selection of the user profile
    """
    profile = request.user.get_profile()
    geoip = hasattr(settings, "GEOIP_PATH")
    if geoip and request.method == "GET" and request.GET.get('ip') == "1":
        from django.contrib.gis.utils import GeoIP
        g = GeoIP()
        c = g.city(request.META.get("REMOTE_ADDR"))
        if c and c.get("latitude") and c.get("longitude"):
            profile.latitude = "%.6f" % c.get("latitude")
            profile.longitude = "%.6f" % c.get("longitude")
            profile.location = unicode(c.get("city"), "latin1")

    if request.method == "POST":
        form = UserLocationForm(request.POST, instance=profile)
        if form.is_valid():
            form.save()
            messages.success(request, _("Your profile information has been updated successfully."), fail_silently=True)

            #signal_responses = signals.post_signal.send(sender=location, request=request, form=form)
            #last_response = signals.last_response(signal_responses)
            #if last_response:
            #    return last_response

    else:
        form = UserLocationForm(instance=profile)

    #signals.context_signal.send(sender=location, request=request, context=data)
    return render_to_response("map/location_form_update.html", \
        { 'GOOGLE_MAPS_API_KEY': settings.MAP_GOOGLE_MAPS_API_KEY, \
        'form': form, 'geoip': geoip }, context_instance=RequestContext(request))
开发者ID:hawkerpl,项目名称:k2,代码行数:35,代码来源:views.py

示例5: test04_city

# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import city [as 别名]
    def test04_city(self):
        "Testing GeoIP city querying methods."
        g = GeoIP(country='<foo>')

        addr = '130.80.29.3'
        fqdn = 'chron.com'
        for query in (fqdn, addr):
            # Country queries should still work.
            for func in (g.country_code, g.country_code_by_addr, g.country_code_by_name):
                self.assertEqual('US', func(query))
            for func in (g.country_name, g.country_name_by_addr, g.country_name_by_name):
                self.assertEqual('United States', func(query))
            self.assertEqual({'country_code' : 'US', 'country_name' : 'United States'},
                             g.country(query))

            # City information dictionary.
            d = g.city(query)
            self.assertEqual('USA', d['country_code3'])
            self.assertEqual('Houston', d['city'])
            self.assertEqual('TX', d['region'])
            self.assertEqual(713, d['area_code'])
            geom = g.geos(query)
            self.failIf(not isinstance(geom, GEOSGeometry))
            lon, lat = (-95.3670, 29.7523)
            lat_lon = g.lat_lon(query)
            lat_lon = (lat_lon[1], lat_lon[0])
            for tup in (geom.tuple, g.coords(query), g.lon_lat(query), lat_lon):
                self.assertAlmostEqual(lon, tup[0], 4)
                self.assertAlmostEqual(lat, tup[1], 4)
开发者ID:GoSteven,项目名称:Diary,代码行数:31,代码来源:test_geoip.py

示例6: neighborhood_monitoring

# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import city [as 别名]
def neighborhood_monitoring(request,
                          template="geotags/view_neighborhood_monitoring.html",
                          content_type_name=None, distance_lt_km=None):
    """
    Direct the user to a template that is able to render the `kml_neighborhood_feed`
    on a google map. This feed can be restricted based on the content type of
    the element you want to get.
    """
    if distance_lt_km == None:
        distance_lt_km = 10
    gip=GeoIP()
    if request.META["REMOTE_ADDR"] != "127.0.0.1":
        user_ip = request.META["REMOTE_ADDR"]
    else:
        user_ip = "populous.com"
    user_location_pnt = gip.geos(user_ip)

    kml_feed = reverse("geotags-kml_neighborhood_feed",
                       kwargs={"distance_lt_km":distance_lt_km})
    criteria_pnt = {
        "point__distance_lt" : (user_location_pnt,
                                D(km=float(distance_lt_km))
                                )
            }
    geotag_points = Point.objects.filter(**criteria_pnt).distance(user_location_pnt).order_by("-distance")
    context = RequestContext(request, {
        "user_ip" : user_ip,
        "user_location_pnt" : user_location_pnt,
        "geotag_points" : geotag_points,
        "google_key" : settings.GOOGLE_MAPS_API_KEY,
        "user_city" : gip.city(user_ip),
        "kml_feed" : kml_feed,
    })
    return render_to_response(template,context_instance=context)
开发者ID:uclastudentmedia,项目名称:django-geotagging,代码行数:36,代码来源:views.py

示例7: location

# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import city [as 别名]
def location(request):
    """
    Location selection of the user profile
    """
    profile, created = Profile.objects.get_or_create(user=request.user)
    geoip = hasattr(settings, "GEOIP_PATH")
    if geoip and request.method == "GET" and request.GET.get("ip") == "1":
        from django.contrib.gis.utils import GeoIP

        g = GeoIP()
        c = g.city(request.META.get("REMOTE_ADDR"))
        if c and c.get("latitude") and c.get("longitude"):
            profile.latitude = "%.6f" % c.get("latitude")
            profile.longitude = "%.6f" % c.get("longitude")
            profile.country = c.get("country_code")
            profile.location = unicode(c.get("city"), "latin1")

    if request.method == "POST":
        form = LocationForm(request.POST, instance=profile)
        if form.is_valid():
            form.save()
            request.user.message_set.create(message=_("Your profile information has been updated successfully."))

            signal_responses = signals.post_signal.send(sender=location, request=request, form=form)
            last_reponse = signals.last_response(signal_responses)
            if last_reponse:
                return last_response

    else:
        form = LocationForm(instance=profile)

    template = "userprofile/profile/location.html"
    data = {"section": "location", "GOOGLE_MAPS_API_KEY": GOOGLE_MAPS_API_KEY, "form": form, "geoip": geoip}
    signals.context_signal.send(sender=location, request=request, context=data)
    return render_to_response(template, data, context_instance=RequestContext(request))
开发者ID:pahaz,项目名称:django-profile,代码行数:37,代码来源:views.py

示例8: get_local

# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import city [as 别名]
def get_local(ip):
	from django.contrib.gis.utils import GeoIP
	g = GeoIP()
	ip = request.META.get('REMOTE_ADDR', None)
	if ip:
		city = g.city(ip)['city']
	else:
		city = 'Sao Paulo' # default city	
	return city
开发者ID:diegolirio,项目名称:poaense,代码行数:11,代码来源:views.py

示例9: whereami

# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import city [as 别名]
def whereami(request):
	g = GeoIP()
	remote_ip = request.META['REMOTE_ADDR']
	if remote_ip == '127.0.0.1':
	    remote_ip = get_my_ip()
	remote_location = g.city(remote_ip)
	if remote_location:
	    return render_to_response('gmaps.html', {'remote_location': remote_location, 'GOOGLE_MAPS_API_KEY':settings.GOOGLE_MAPS_API_KEY})
	else: # localhost ip cannot be found
	    return render_to_response('not_found.html')
开发者ID:EmereArco,项目名称:geodjango-basic-apps,代码行数:12,代码来源:views.py

示例10: _cidade_cliente

# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import city [as 别名]
def _cidade_cliente(request):
     #geo
    ip_address=request.META.get('REMOTE_ADDR') 
    g = GeoIP()
    #local_full_cliente = g.city(ip_address)
    local_full_cliente = g.city('201.22.164.216')
    cidade_cliente = local_full_cliente.get('city')
    uni = cidade_cliente.decode('cp1252')
    cidade_cliente = uni.encode('utf8')
    return cidade_cliente
开发者ID:Vieceli,项目名称:cupponclipper,代码行数:12,代码来源:views.py

示例11: get_geoip_coords

# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import city [as 别名]
def get_geoip_coords(request):
    lat, lng = '', ''
    geoip = GeoIP()
    # TODO: Middleware to set REMOTE_ADDR from HTTP_X_FORWARDED_FOR.
    remote_addr = get_remote_ip(request)
    geoip_result = geoip.city(remote_addr)
    if geoip_result:
        lat = geoip_result.get('latitude', '')
        lng = geoip_result.get('longitude', '')
    return lat, lng
开发者ID:mpants,项目名称:villagescc,代码行数:12,代码来源:views.py

示例12: getLocation

# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import city [as 别名]
def getLocation(self):

    g = GeoIP()
    ip = request.META.get("REMOTE_ADDR", None)
    if ip:
        city = g.city(ip)["city"]
        return city

    else:
        print "nothing"
开发者ID:subhodip,项目名称:aviyal,代码行数:12,代码来源:getLocation.py

示例13: get_geo

# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import city [as 别名]
def get_geo(video):
    latitude = 0.0
    longitude = 0.0
    g = GeoIP()
    if settings.GEOIP_PATH:
        try:
            data = g.city(video.job_set.all()[0].ip)
            if data:
                latitude = float(data['latitude'])
                longitude = float(data['longitude'])
        except StandardError, e:
            LOGGER.debug(str(e))
开发者ID:megamidiagroup,项目名称:tcd_offline,代码行数:14,代码来源:youtube.py

示例14: whereis

# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import city [as 别名]
def whereis(request, ip):
	g = GeoIP()
	ip_match = re.compile(r'\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b')
	try:
	    remote_ip = ip_match.findall(ip)[0]
	except:
	    remote_ip = ''
	remote_location = g.city(remote_ip)
	if remote_location:
	    return render_to_response('gmaps.html', {'remote_location': remote_location, 'GOOGLE_MAPS_API_KEY':settings.GOOGLE_MAPS_API_KEY})
	else: # localhost ip cannot be found
	    return render_to_response('not_found.html')
开发者ID:EmereArco,项目名称:geodjango-basic-apps,代码行数:14,代码来源:views.py

示例15: process_request

# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import city [as 别名]
    def process_request(self, request):

        request.LOCATION_DATA = False
        ip = request.META.get('HTTP_X_FORWARDED_FOR', '')\
            or request.META.get('HTTP_X_REAL_IP', '')\
            or request.META.get('REMOTE_ADDR', '')

        if ip:
            g = GeoIP()
            if settings.DEBUG:
                ip = '178.92.248.224'
            request.LOCATION_DATA = g.city(ip)
开发者ID:shalakhin,项目名称:quester-me,代码行数:14,代码来源:middleware.py


注:本文中的django.contrib.gis.utils.GeoIP.city方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。