mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 11:31:08 +00:00
Associated expanded editions with correct work
This commit is contained in:
parent
7b65291a59
commit
3faacffaca
2 changed files with 16 additions and 13 deletions
|
@ -73,7 +73,7 @@ class AbstractMinimalConnector(ABC):
|
|||
return get_data(remote_id, **kwargs)
|
||||
|
||||
@abstractmethod
|
||||
def get_or_create_book(self, remote_id):
|
||||
def get_or_create_book(self, remote_id, work=None):
|
||||
"""pull up a book record by whatever means possible"""
|
||||
|
||||
@abstractmethod
|
||||
|
@ -109,7 +109,7 @@ class AbstractConnector(AbstractMinimalConnector):
|
|||
return False
|
||||
return True
|
||||
|
||||
def get_or_create_book(self, remote_id):
|
||||
def get_or_create_book(self, remote_id, work=None):
|
||||
"""translate arbitrary json into an Activitypub dataclass"""
|
||||
# first, check if we have the origin_id saved
|
||||
existing = models.Edition.find_existing_by_remote_id(
|
||||
|
@ -123,6 +123,7 @@ class AbstractConnector(AbstractMinimalConnector):
|
|||
# load the json
|
||||
data = self.get_book_data(remote_id)
|
||||
mapped_data = dict_from_mappings(data, self.book_mappings)
|
||||
work_data = edition_data = None
|
||||
if self.is_work_data(data):
|
||||
try:
|
||||
edition_data = self.get_edition_from_work_data(data)
|
||||
|
@ -132,17 +133,19 @@ class AbstractConnector(AbstractMinimalConnector):
|
|||
edition_data = data
|
||||
work_data = mapped_data
|
||||
else:
|
||||
edition_data = data
|
||||
if not work:
|
||||
try:
|
||||
work_data = self.get_work_from_edition_data(data)
|
||||
work_data = dict_from_mappings(work_data, self.book_mappings)
|
||||
except (KeyError, ConnectorException):
|
||||
work_data = mapped_data
|
||||
edition_data = data
|
||||
|
||||
if not work_data or not edition_data:
|
||||
if (not work_data and not work) or not edition_data:
|
||||
raise ConnectorException("Unable to load book data: %s" % remote_id)
|
||||
|
||||
with transaction.atomic():
|
||||
if not work:
|
||||
# create activitypub object
|
||||
work_activity = activitypub.Work(**work_data)
|
||||
# this will dedupe automatically
|
||||
|
|
|
@ -137,7 +137,7 @@ class Connector(AbstractConnector):
|
|||
|
||||
for edition_uri in edition_options.get("uris"):
|
||||
remote_id = self.get_remote_id(edition_uri)
|
||||
self.get_or_create_book(remote_id)
|
||||
self.get_or_create_book(remote_id, work=work)
|
||||
|
||||
def get_cover_url(self, cover_blob, *_):
|
||||
"""format the relative cover url into an absolute one:
|
||||
|
|
Loading…
Reference in a new issue