Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Make GeoJSONResponse more flexible. #84

Open
dyve opened this issue Feb 7, 2017 · 0 comments
Open

Make GeoJSONResponse more flexible. #84

dyve opened this issue Feb 7, 2017 · 0 comments

Comments

@dyve
Copy link

dyve commented Feb 7, 2017

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
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant