makinacorpus / django-geojson

django-geojson is a collection of helpers to (de)serialize (Geo)Django objects into GeoJSON.
GNU Lesser General Public License v3.0
259 stars 69 forks source link

Make GeoJSONResponse more flexible. #84

Open dyve opened 7 years ago

dyve commented 7 years ago

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