Include all relevent book data without infinite recusion

This commit is contained in:
Mouse Reeve 2020-05-08 17:36:02 -07:00
parent 0edb9688cb
commit 9beae9cfcd
2 changed files with 9 additions and 6 deletions

View file

@ -1,7 +1,7 @@
''' federate book data '''
from fedireads.settings import DOMAIN
def get_book(book):
def get_book(book, recursive=True):
''' activitypub serialize a book '''
fields = [
@ -42,11 +42,13 @@ def get_book(book):
'published_date': book.published_date.isoformat() if \
book.published_date else None,
}
if book_type == 'Edition':
activity['work'] = book.parent_work.absolute_id
else:
editions = book.edition_set.order_by('default')
activity['editions'] = [get_book(b) for b in editions]
if recursive:
if book_type == 'Edition':
activity['work'] = get_book(book.parent_work, recursive=False)
else:
editions = book.edition_set.order_by('default')
activity['editions'] = [
get_book(b, recursive=False) for b in editions]
for field in fields:
if hasattr(book, field):

View file

@ -55,6 +55,7 @@ class AbstractConnector(ABC):
def create_book(self, key, data, model):
''' create a work or edition from data '''
# we really would rather use an existing book than make a new one
print(data)
match = match_from_mappings(data, self.key_mappings)
if match:
if not isinstance(match, model):