issues.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:issue-reporting 作者: 6aika 项目源码 文件源码
def _apply_geo_filters(self, request, queryset):
        # Strictly speaking these are not queries that should be possible with a GeoReport v2
        # core implementation, but as they do not require extra data in the models, it's worth it
        # to have them available "for free".
        bbox = request.query_params.get('bbox')
        if bbox:
            bbox = parse_bbox(bbox)
            (long1, lat1), (long2, lat2) = bbox
            queryset = queryset.filter(lat__range=(lat1, lat2))
            queryset = queryset.filter(long__range=(long1, long2))

        lat = request.query_params.get('lat')
        lon = request.query_params.get('long')
        radius = request.query_params.get('radius')
        if lat and lon and radius:
            try:
                lat = float(lat)
                lon = float(lon)
                radius = float(radius)
            except ValueError:
                raise APIException('lat/lon/radius must all be valid decimal numbers')
            if not determine_gissiness():
                raise APIException('this installation is not capable of lat/lon/radius queries')
            from django.contrib.gis.db.models.functions import Distance
            from django.contrib.gis.geos import Point
            from django.contrib.gis.measure import D
            point = Point(x=lon, y=lat, srid=4326)
            queryset = queryset.annotate(distance=Distance('location', point))
            queryset = queryset.filter(location__distance_lte=(point, D(m=radius)))
        return queryset
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号