Skip to content

Added Resource.prepare_list method #111

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion restless/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def serialize_list(self, data):
if not getattr(data, 'should_prepare', True):
prepped_data = data.value
else:
prepped_data = [self.prepare(item) for item in data]
prepped_data = self.prepare_list(data)

final_data = self.wrap_list_response(prepped_data)
return self.serializer.serialize(final_data)
Expand All @@ -432,6 +432,20 @@ def serialize_detail(self, data):

return self.serializer.serialize(prepped_data)

def prepare_list(self, data):
"""
Given a collection of data (``objects`` or ``dicts``), this will
potentially go through & reshape the output with the ``self.prepare``
method.

:param data: A collection to prepare for serialization
:type data: list or iterable

:returns: A potentially reshaped collection
:rtype: list
"""
return [self.prepare(item) for item in data]

def prepare(self, data):
"""
Given an item (``object`` or ``dict``), this will potentially go through
Expand Down