django-geojson icon indicating copy to clipboard operation
django-geojson copied to clipboard

Make GeoJSONResponse more flexible.

Open dyve opened this issue 9 years ago • 0 comments

I'd like to submit a pull request to be able to overwrite get_queryset. Code below, would this be welcome?

def get_geojson_data(self, context):
    # Might even take object_list from context by default
    return self.get_queryset()

def render_to_response(self, context, **response_kwargs):
    """
    Returns a JSON response, transforming 'context' to make the payload.
    """
    serializer = GeoJSONSerializer()
    response = self.response_class(**response_kwargs)
    # Might want to rename this to data
    queryset = self.get_geojson_data(context)

    options = dict(
        properties=self.properties,
        precision=self.precision,
        simplify=self.simplify,
        srid=self.srid,
        geometry_field=self.geometry_field,
        force2d=self.force2d,
        bbox=self.bbox,
        bbox_auto=self.bbox_auto,
        use_natural_keys=self.use_natural_keys,
    )
    serializer.serialize(
        queryset,
        stream=response,
        ensure_ascii=False,
        **options,
    )
    return response

dyve avatar Feb 07 '17 10:02 dyve