Beispiel #1
0
    def test_is_close_enough(self):
        origin = Geolocation(lat=12.2, lon=1.0)
        to = origin
        self.assertTrue(geolocation.is_close_enough(origin, to, 0))

        origin = Geolocation(lat=48.895603, lon=2.322858)  # 32 rue des epinettes
        to = Geolocation(lat=48.883588, lon=2.327195)  # place de clichy
        self.assertTrue(geolocation.is_close_enough(origin, to, 1.4))  # ~ 1.373 km
        self.assertFalse(geolocation.is_close_enough(origin, to, 1.3))  # ~ 1.373 km
Beispiel #2
0
    def filter_distance(self, distance, geoloc, queryset):
        """
        Filter the queryset using distance and the user that is querying.

        :param distance:        the distance to look for
        :param geoloc:          the user geolocation that does the query
        :param queryset:        the queryset
        """
        distance = float(distance)  # distance in km
        condition = lambda o: o.is_geolocated and is_close_enough(geoloc, o.geolocation, distance)
        return [o for o in queryset if condition(o)]