本文整理汇总了Python中django.contrib.gis.utils.GeoIP类的典型用法代码示例。如果您正苦于以下问题:Python GeoIP类的具体用法?Python GeoIP怎么用?Python GeoIP使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GeoIP类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: location
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))
示例2: location
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))
示例3: location
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))
示例4: process_request
def process_request(self, request):
from django.conf import settings
from meegloo.international.models import Country
try:
from django.contrib.gis.utils import GeoIP
except ImportError:
request.country = Country.objects.get(
pk = getattr(settings, 'COUNTRY_ID')
)
return
g = GeoIP()
ip = request.META.get('HTTP_X_FORWARDED_FOR',
request.META.get('REMOTE_IP', request.META.get('REMOTE_ADDR'))
)
if ip != '127.0.0.1':
d = g.country(ip)
code = d['country_code']
request.country = Country.objects.get(code = code)
else:
pk = getattr(settings, 'COUNTRY_ID')
request.country = Country.objects.get(pk = pk)
示例5: neighborhood_monitoring
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)
示例6: kml_neighborhood_feed
def kml_neighborhood_feed(request, template="geotags/geotags.kml",
distance_lt_km=None ,content_type_name=None,
object_id=None):
"""
Return a KML feed of all the geotags in a around the user. This view takes
an argument called `distance_lt_km` which is the radius of the permeter your
are searching in. This feed can be restricted based on the content type of
the element you want to get.
"""
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)
criteria_pnt = {
"point__distance_lt" : (user_location_pnt,
D(km=float(distance_lt_km))
)
}
if content_type_name:
criteria_pnt["content_type__name"]==content_type_name
geotags = Point.objects.filter(**criteria_pnt)
context = RequestContext(request, {
'places' : geotags.kml(),
})
return render_to_kml(template,context_instance=context)
示例7: get_local
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
示例8: get_geoip_coords
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
示例9: whereami
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')
示例10: _cidade_cliente
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
示例11: getLocation
def getLocation(self):
g = GeoIP()
ip = request.META.get("REMOTE_ADDR", None)
if ip:
city = g.city(ip)["city"]
return city
else:
print "nothing"
示例12: get_geoIP
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
示例13: process_request
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)
示例14: whereis
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')
示例15: get_geo
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))