Esempio n. 1
0
    def get(self, request, *args, **kwargs):
        if 'q' in request.GET:
            search_term = request.GET['q']
            geo_levels = request.GET.get('geolevels', None)
            return render_json_to_response(
                {'results': get_locations(search_term, geo_levels)}
            )

        if 'coords' in request.GET:
            # coords=lat,lng&coords=lat,lng
            # we only want the first 3, to limit our outgoing requests
            coords = request.GET.getlist('coords')[:3]

            # unpack
            pairs = [c.split(',', 1) for c in coords if ',' in c]

            places = set()
            for lat, lng in pairs:
                try:
                    places.update(get_locations_from_coords(latitude=lat.strip(), longitude=lng.strip()))
                except SearchException as e:
                    logger.warn("Error looking up places for (%s, %s): %s" % (lat, lng, e.message), exc_info=e)

            ordering = {County: 0, Country: 1}
            places = sorted(places, key=lambda o: [ordering[o.__class__], o.name, o.code])

            return render_json_to_response(
                {'results': [p.as_dict() for p in places]}
            )


        return HttpResponseBadRequest('"q" or "coords" parameter is required')
Esempio n. 2
0
    def get_context_data(self, *args, **kwargs):
        page_context = {}
        lat = self.request.GET.get("lat", None)
        lon = self.request.GET.get("lon", None)

        if lat and lon:
            places = get_locations_from_coords(latitude=lat, longitude=lon)
            page_context.update({"location": {"lat": lat, "lon": lon}, "places": places})

        return page_context
Esempio n. 3
0
    def get_context_data(self, *args, **kwargs):
        page_context = {}
        lat = self.request.GET.get('lat', None)
        lon = self.request.GET.get('lon', None)

        if lat and lon:
            places = get_locations_from_coords(latitude=lat, longitude=lon)
            page_context.update({
                'location': {
                    'lat': lat,
                    'lon': lon
                },
                'places': places
            })

        return page_context
Esempio n. 4
0
    def get_context_data(self, *args, **kwargs):
        page_context = {}
        lat = self.request.GET.get('lat', None)
        lon = self.request.GET.get('lon', None)

        if lat and lon:
            places = get_locations_from_coords(latitude=lat, longitude=lon)
            page_context.update({
                'location': {
                    'lat': lat,
                    'lon': lon
                },
                'places': places
            })

        return page_context