Handle various link generation needs

This commit is contained in:
Mouse Reeve 2021-12-05 13:38:15 -08:00
parent 4085714764
commit 071da7d4fb
3 changed files with 13 additions and 4 deletions

View file

@ -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)

View file

@ -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"""

View file

@ -92,7 +92,7 @@
{% trans "View on Inventaire" %}
</a>
{% if request.user.is_authenticated and perms.bookwyrm.edit_book %}
<form name="ol-update" method="POST" action="{% url 'author-update-remote' author.id 'inventaire' %}">
<form name="ol-update" method="POST" action="{% url 'author-update-remote' author.id 'inventaire.io' %}">
{% csrf_token %}
<button class="button is-small" type="submit">{% trans "Update from Inventaire" %}</button>
</form>