diff --git a/bookwyrm/connectors/abstract_connector.py b/bookwyrm/connectors/abstract_connector.py index 4b1f6e58..bb2bfb6f 100644 --- a/bookwyrm/connectors/abstract_connector.py +++ b/bookwyrm/connectors/abstract_connector.py @@ -195,14 +195,18 @@ class AbstractConnector(AbstractMinimalConnector): model=models.Author, overwrite=False, instance=instance ) + def get_remote_id_from_model(self, obj): + """given the data stored, how can we look this up""" + return getattr(obj, getattr(self, "generated_remote_link_field")) + def update_author_from_remote(self, obj): """load the remote data from this connector and add it to an existing author""" - remote_id = getattr(obj, getattr(self, "generated_remote_link_field")) + remote_id = self.get_remote_id_from_model(obj) return self.get_or_create_author(remote_id, instance=obj) def update_book_from_remote(self, obj): """load the remote data from this connector and add it to an existing book""" - remote_id = getattr(obj, getattr(self, "generated_remote_link_field")) + remote_id = self.get_remote_id_from_model(obj) data = self.get_book_data(remote_id) return self.create_edition_from_data(obj.parent_work, data, instance=obj) diff --git a/bookwyrm/connectors/inventaire.py b/bookwyrm/connectors/inventaire.py index bc5b3f68..45d0546f 100644 --- a/bookwyrm/connectors/inventaire.py +++ b/bookwyrm/connectors/inventaire.py @@ -11,7 +11,7 @@ from .connector_manager import ConnectorException class Connector(AbstractConnector): """instantiate a connector for inventaire""" - generated_remote_link_field = "inventaire_link" + generated_remote_link_field = "inventaire_id" def __init__(self, identifier): super().__init__(identifier) @@ -212,6 +212,11 @@ class Connector(AbstractConnector): return "" return data.get("extract") + def get_remote_id_from_model(self, obj): + """use get_remote_id to figure out the link from a model obj""" + remote_id_value = getattr(obj, self.inventaire_id) + return self.get_remote_id(remote_id_value) + def get_language_code(options, code="en"): """when there are a bunch of translation but we need a single field""" diff --git a/bookwyrm/templates/author/author.html b/bookwyrm/templates/author/author.html index 6e93d313..bf2c8f3f 100644 --- a/bookwyrm/templates/author/author.html +++ b/bookwyrm/templates/author/author.html @@ -92,7 +92,7 @@ {% trans "View on Inventaire" %} {% if request.user.is_authenticated and perms.bookwyrm.edit_book %} -
+ {% csrf_token %}