Handle various link generation needs
This commit is contained in:
parent
4085714764
commit
071da7d4fb
|
@ -195,14 +195,18 @@ class AbstractConnector(AbstractMinimalConnector):
|
||||||
model=models.Author, overwrite=False, instance=instance
|
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):
|
def update_author_from_remote(self, obj):
|
||||||
"""load the remote data from this connector and add it to an existing author"""
|
"""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)
|
return self.get_or_create_author(remote_id, instance=obj)
|
||||||
|
|
||||||
def update_book_from_remote(self, obj):
|
def update_book_from_remote(self, obj):
|
||||||
"""load the remote data from this connector and add it to an existing book"""
|
"""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)
|
data = self.get_book_data(remote_id)
|
||||||
return self.create_edition_from_data(obj.parent_work, data, instance=obj)
|
return self.create_edition_from_data(obj.parent_work, data, instance=obj)
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ from .connector_manager import ConnectorException
|
||||||
class Connector(AbstractConnector):
|
class Connector(AbstractConnector):
|
||||||
"""instantiate a connector for inventaire"""
|
"""instantiate a connector for inventaire"""
|
||||||
|
|
||||||
generated_remote_link_field = "inventaire_link"
|
generated_remote_link_field = "inventaire_id"
|
||||||
|
|
||||||
def __init__(self, identifier):
|
def __init__(self, identifier):
|
||||||
super().__init__(identifier)
|
super().__init__(identifier)
|
||||||
|
@ -212,6 +212,11 @@ class Connector(AbstractConnector):
|
||||||
return ""
|
return ""
|
||||||
return data.get("extract")
|
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"):
|
def get_language_code(options, code="en"):
|
||||||
"""when there are a bunch of translation but we need a single field"""
|
"""when there are a bunch of translation but we need a single field"""
|
||||||
|
|
|
@ -92,7 +92,7 @@
|
||||||
{% trans "View on Inventaire" %}
|
{% trans "View on Inventaire" %}
|
||||||
</a>
|
</a>
|
||||||
{% if request.user.is_authenticated and perms.bookwyrm.edit_book %}
|
{% 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 %}
|
{% csrf_token %}
|
||||||
<button class="button is-small" type="submit">{% trans "Update from Inventaire" %}</button>
|
<button class="button is-small" type="submit">{% trans "Update from Inventaire" %}</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
Loading…
Reference in New Issue