Example #1
0
def distance_argument(d):
    m = re.match("^([0-9.]+)([a-zA-Z]+)$", d)

    if not m:
        raise ValueError(f"{d} n'est pas une mesure de distance correcte")

    return DistanceMeasure(**{m.group(2): float(m.group(1))})
Example #2
0
 def filter_queryset(self, request, queryset, view):
     user_location = request.query_params.get('user_location', None)
     if user_location and queryset.model is ServiceAtLocation:
         location = ProximityParser(user_location)
         location_point = Point(location.latitude,
                                location.longitude,
                                srid=SRID)
         queryset = (queryset.annotate(
             distance=Distance('location__point', location_point)).filter(
                 distance__lte=DistanceMeasure(km=25)))
     return queryset
Example #3
0
 def convert_value(self, value, expression, connection, context):
     if value is None:
         return None
     dist_att = None
     geo_field = self.geo_field
     if geo_field.geodetic(connection):
         if connection.features.supports_distance_geodetic:
             dist_att = 'm'
     else:
         dist_att = geo_field.units_name(connection)
     if dist_att:
         return DistanceMeasure(**{dist_att: value})
     return value
Example #4
0
 def convert_value(self, value, expression, connection, context):
     if value is None:
         return None
     geo_field = self.geo_field
     if geo_field.geodetic(connection):
         dist_att = 'm'
     else:
         units = geo_field.units_name(connection)
         if units:
             dist_att = DistanceMeasure.unit_attname(units)
         else:
             dist_att = None
     if dist_att:
         return DistanceMeasure(**{dist_att: value})
     return value
Example #5
0
 def get_events_full_text_search(self, text_query, min_date, max_date,
                                 location, distance_max):
     if not text_query:
         return []
     qs = self.get_queryset()
     q = PrefixSearchQuery(text_query, config="fr")
     qs = (qs.annotate(rank=SearchRank(F("search"), q)).filter(
         rank__gt=0).order_by("-rank").filter(
             visibility=Event.VISIBILITY_PUBLIC))
     if min_date:
         qs = qs.filter(start_time__gt=min_date)
     if max_date:
         qs = qs.filter(start_time__lt=(max_date + timedelta(days=1)))
     if location and distance_max:
         qs = qs.annotate(
             distance=Distance("coordinates", location)).filter(
                 distance__lte=DistanceMeasure(km=int(distance_max)))
     return qs
Example #6
0
 def convert_value(self, value, expression, connection, context):
     if value is None:
         return None
     d = DistanceMeasure()
     d.standard = value
     return d
Example #7
0
 def __init__(self, **kwargs):
     distance = DistanceMeasure(**kwargs)
     super().__init__(distance.standard)