Skip to content
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

Community field dumping #1084

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def parse_pid(self, value):
return value
try:
return UUID(value)
except (TypeError, ValueError) as e:
except (TypeError, ValueError):
return value

def resolve(self, pid_value, registered_only=True):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,13 @@ def __get__(self, record, owner=None):
if record is None:
return self._context_cls(self, owner)
return self.obj(record)

def post_dump(self, record, data, dumper=None):
"""Dump the communities field."""
comms = getattr(record, self.attr_name)
res = comms.to_dict()
res["entries"] = [
# TODO: Only keep fields we want to dump
comm.dumps() for comm in comms
]
data[self.key] = res
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ def __iter__(self):
# Iterate (sort by identifier to ensure consistent results)
return (self._communities_cache[c] for c in sorted(self._communities_ids))

def __getitem__(self, community_id):
"""Get a community by ID."""
if community_id in self._communities_cache:
return self._communities_cache[community_id]
return self._lookup_community(self._to_id(community_id))

@property
def ids(self):
"""Get communities ids."""
Expand Down
3 changes: 1 addition & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,8 @@ def fake_communities(
community_type_record,
community_types,
):
"""Fake Communities."""
data = deepcopy(minimal_community)
"""Multiple community created and posted to test search functionality."""
data = deepcopy(minimal_community)
N = 4

for type_, ind in itertools.product(community_types, list(range(N))):
Expand Down
Loading