forked from mirrors/bookwyrm
Adds separate view and load links for book search results
This commit is contained in:
parent
d482c66ad4
commit
fba44206ac
4 changed files with 9 additions and 5 deletions
|
@ -25,7 +25,7 @@ class Book(ActivityObject):
|
||||||
publishedDate: str = ""
|
publishedDate: str = ""
|
||||||
|
|
||||||
openlibraryKey: str = None
|
openlibraryKey: str = None
|
||||||
inventiareId: str = None
|
inventaireId: str = None
|
||||||
librarythingKey: str = None
|
librarythingKey: str = None
|
||||||
goodreadsKey: str = None
|
goodreadsKey: str = None
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ class Author(ActivityObject):
|
||||||
aliases: List[str] = field(default_factory=lambda: [])
|
aliases: List[str] = field(default_factory=lambda: [])
|
||||||
bio: str = ""
|
bio: str = ""
|
||||||
openlibraryKey: str = None
|
openlibraryKey: str = None
|
||||||
inventiareId: str = None
|
inventaireId: str = None
|
||||||
librarythingKey: str = None
|
librarythingKey: str = None
|
||||||
goodreadsKey: str = None
|
goodreadsKey: str = None
|
||||||
wikipediaLink: str = ""
|
wikipediaLink: str = ""
|
||||||
|
|
|
@ -263,6 +263,7 @@ class SearchResult:
|
||||||
title: str
|
title: str
|
||||||
key: str
|
key: str
|
||||||
connector: object
|
connector: object
|
||||||
|
view_link: str = None
|
||||||
author: str = None
|
author: str = None
|
||||||
year: str = None
|
year: str = None
|
||||||
cover: str = None
|
cover: str = None
|
||||||
|
@ -284,7 +285,7 @@ class Mapping:
|
||||||
""" associate a local database field with a field in an external dataset """
|
""" associate a local database field with a field in an external dataset """
|
||||||
|
|
||||||
def __init__(self, local_field, remote_field=None, formatter=None):
|
def __init__(self, local_field, remote_field=None, formatter=None):
|
||||||
noop = lambda x: x
|
noop = lambda x, *_: x
|
||||||
|
|
||||||
self.local_field = local_field
|
self.local_field = local_field
|
||||||
self.remote_field = remote_field or local_field
|
self.remote_field = remote_field or local_field
|
||||||
|
|
|
@ -11,9 +11,11 @@ class Connector(AbstractConnector):
|
||||||
def __init__(self, identifier):
|
def __init__(self, identifier):
|
||||||
super().__init__(identifier)
|
super().__init__(identifier)
|
||||||
|
|
||||||
|
get_remote_id = lambda a, *args: self.base_url + a
|
||||||
self.book_mappings = [
|
self.book_mappings = [
|
||||||
Mapping("title", remote_field="wdt:P1476", formatter=get_claim),
|
Mapping("title", remote_field="wdt:P1476", formatter=get_claim),
|
||||||
Mapping("id", remote_field="id"),
|
Mapping("id", remote_field="key", formatter=get_remote_id),
|
||||||
|
Mapping("inventaireId", remote_field="id"),
|
||||||
Mapping("cover", remote_field="image", formatter=self.get_cover_url),
|
Mapping("cover", remote_field="image", formatter=self.get_cover_url),
|
||||||
Mapping("isbn13", remote_field="wdt:P212", formatter=get_claim),
|
Mapping("isbn13", remote_field="wdt:P212", formatter=get_claim),
|
||||||
Mapping("isbn10", remote_field="wdt:P957", formatter=get_claim),
|
Mapping("isbn10", remote_field="wdt:P957", formatter=get_claim),
|
||||||
|
@ -35,6 +37,7 @@ class Connector(AbstractConnector):
|
||||||
return SearchResult(
|
return SearchResult(
|
||||||
title=search_result.get("label"),
|
title=search_result.get("label"),
|
||||||
key="{:s}{:s}".format(self.books_url, search_result.get("uri")),
|
key="{:s}{:s}".format(self.books_url, search_result.get("uri")),
|
||||||
|
view_link="{:s}{:s}".format(self.base_url, search_result.get("uri")),
|
||||||
cover=cover,
|
cover=cover,
|
||||||
connector=self,
|
connector=self,
|
||||||
)
|
)
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<p>
|
<p>
|
||||||
<strong>
|
<strong>
|
||||||
<a href="{{ result.key }}"{% if remote_result %} rel=”noopener” target="_blank"{% endif %}>{{ result.title }}</a>
|
<a href="{{ result.view_link|default:result.key }}"{% if remote_result %} rel=”noopener” target="_blank"{% endif %}>{{ result.title }}</a>
|
||||||
</strong>
|
</strong>
|
||||||
{% if result.author %}
|
{% if result.author %}
|
||||||
{% blocktrans with author=result.author %}by {{ author }}{% endblocktrans %}{% endif %}{% if result.year %} ({{ result.year }})
|
{% blocktrans with author=result.author %}by {{ author }}{% endblocktrans %}{% endif %}{% if result.year %} ({{ result.year }})
|
||||||
|
|
Loading…
Reference in a new issue