mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-23 08:36:32 +00:00
Merge pull request #1891 from bookwyrm-social/openlibrary-author-fields
Openlibrary author fields
This commit is contained in:
commit
1a8f4a916e
6 changed files with 127 additions and 14 deletions
|
@ -16,6 +16,9 @@ class BookData(ActivityObject):
|
|||
librarythingKey: str = None
|
||||
goodreadsKey: str = None
|
||||
bnfId: str = None
|
||||
viaf: str = None
|
||||
wikidata: str = None
|
||||
asin: str = None
|
||||
lastEditedBy: str = None
|
||||
links: List[str] = field(default_factory=lambda: [])
|
||||
fileLinks: List[str] = field(default_factory=lambda: [])
|
||||
|
@ -27,8 +30,8 @@ class Book(BookData):
|
|||
"""serializes an edition or work, abstract"""
|
||||
|
||||
title: str
|
||||
sortTitle: str = ""
|
||||
subtitle: str = ""
|
||||
sortTitle: str = None
|
||||
subtitle: str = None
|
||||
description: str = ""
|
||||
languages: List[str] = field(default_factory=lambda: [])
|
||||
series: str = ""
|
||||
|
@ -53,7 +56,6 @@ class Edition(Book):
|
|||
isbn10: str = ""
|
||||
isbn13: str = ""
|
||||
oclcNumber: str = ""
|
||||
asin: str = ""
|
||||
pages: int = None
|
||||
physicalFormat: str = ""
|
||||
physicalFormatDetail: str = ""
|
||||
|
|
|
@ -68,7 +68,30 @@ class Connector(AbstractConnector):
|
|||
Mapping("born", remote_field="birth_date"),
|
||||
Mapping("died", remote_field="death_date"),
|
||||
Mapping("bio", formatter=get_description),
|
||||
Mapping("isni", remote_field="remote_ids", formatter=get_isni),
|
||||
Mapping(
|
||||
"isni",
|
||||
remote_field="remote_ids",
|
||||
formatter=lambda b: get_dict_field(b, "isni"),
|
||||
),
|
||||
Mapping(
|
||||
"asin",
|
||||
remote_field="remote_ids",
|
||||
formatter=lambda b: get_dict_field(b, "amazon"),
|
||||
),
|
||||
Mapping(
|
||||
"viaf",
|
||||
remote_field="remote_ids",
|
||||
formatter=lambda b: get_dict_field(b, "viaf"),
|
||||
),
|
||||
Mapping(
|
||||
"wikidata",
|
||||
remote_field="remote_ids",
|
||||
formatter=lambda b: get_dict_field(b, "wikidata"),
|
||||
),
|
||||
Mapping(
|
||||
"wikipedia_link", remote_field="links", formatter=get_wikipedia_link
|
||||
),
|
||||
Mapping("inventaire_id", remote_field="links", formatter=get_inventaire_id),
|
||||
]
|
||||
|
||||
def get_book_data(self, remote_id):
|
||||
|
@ -227,11 +250,38 @@ def get_languages(language_blob):
|
|||
return langs
|
||||
|
||||
|
||||
def get_isni(remote_ids_blob):
|
||||
def get_dict_field(blob, field_name):
|
||||
"""extract the isni from the remote id data for the author"""
|
||||
if not remote_ids_blob or not isinstance(remote_ids_blob, dict):
|
||||
if not blob or not isinstance(blob, dict):
|
||||
return None
|
||||
return remote_ids_blob.get("isni")
|
||||
return blob.get(field_name)
|
||||
|
||||
|
||||
def get_wikipedia_link(links):
|
||||
"""extract wikipedia links"""
|
||||
if not isinstance(links, list):
|
||||
return None
|
||||
|
||||
for link in links:
|
||||
if not isinstance(link, dict):
|
||||
continue
|
||||
if link.get("title") == "wikipedia":
|
||||
return link.get("url")
|
||||
return None
|
||||
|
||||
|
||||
def get_inventaire_id(links):
|
||||
"""extract and format inventaire ids"""
|
||||
if not isinstance(links, list):
|
||||
return None
|
||||
|
||||
for link in links:
|
||||
if not isinstance(link, dict):
|
||||
continue
|
||||
if link.get("title") == "inventaire.io":
|
||||
iv_link = link.get("url")
|
||||
return iv_link.split("/")[-1]
|
||||
return None
|
||||
|
||||
|
||||
def pick_default_edition(options):
|
||||
|
|
58
bookwyrm/migrations/0135_auto_20220217_1624.py
Normal file
58
bookwyrm/migrations/0135_auto_20220217_1624.py
Normal file
|
@ -0,0 +1,58 @@
|
|||
# Generated by Django 3.2.12 on 2022-02-17 16:24
|
||||
|
||||
import bookwyrm.models.fields
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("bookwyrm", "0134_announcement_display_type"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name="author",
|
||||
old_name="viaf_id",
|
||||
new_name="viaf",
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name="edition",
|
||||
name="asin",
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="author",
|
||||
name="asin",
|
||||
field=bookwyrm.models.fields.CharField(
|
||||
blank=True, max_length=255, null=True
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="author",
|
||||
name="wikidata",
|
||||
field=bookwyrm.models.fields.CharField(
|
||||
blank=True, max_length=255, null=True
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="book",
|
||||
name="asin",
|
||||
field=bookwyrm.models.fields.CharField(
|
||||
blank=True, max_length=255, null=True
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="book",
|
||||
name="viaf",
|
||||
field=bookwyrm.models.fields.CharField(
|
||||
blank=True, max_length=255, null=True
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="book",
|
||||
name="wikidata",
|
||||
field=bookwyrm.models.fields.CharField(
|
||||
blank=True, max_length=255, null=True
|
||||
),
|
||||
),
|
||||
]
|
|
@ -21,9 +21,6 @@ class Author(BookDataModel):
|
|||
isni = fields.CharField(
|
||||
max_length=255, blank=True, null=True, deduplication_field=True
|
||||
)
|
||||
viaf_id = fields.CharField(
|
||||
max_length=255, blank=True, null=True, deduplication_field=True
|
||||
)
|
||||
gutenberg_id = fields.CharField(
|
||||
max_length=255, blank=True, null=True, deduplication_field=True
|
||||
)
|
||||
|
|
|
@ -46,6 +46,15 @@ class BookDataModel(ObjectMixin, BookWyrmModel):
|
|||
bnf_id = fields.CharField( # Bibliothèque nationale de France
|
||||
max_length=255, blank=True, null=True, deduplication_field=True
|
||||
)
|
||||
viaf = fields.CharField(
|
||||
max_length=255, blank=True, null=True, deduplication_field=True
|
||||
)
|
||||
wikidata = fields.CharField(
|
||||
max_length=255, blank=True, null=True, deduplication_field=True
|
||||
)
|
||||
asin = fields.CharField(
|
||||
max_length=255, blank=True, null=True, deduplication_field=True
|
||||
)
|
||||
search_vector = SearchVectorField(null=True)
|
||||
|
||||
last_edited_by = fields.ForeignKey(
|
||||
|
@ -271,9 +280,6 @@ class Edition(Book):
|
|||
oclc_number = fields.CharField(
|
||||
max_length=255, blank=True, null=True, deduplication_field=True
|
||||
)
|
||||
asin = fields.CharField(
|
||||
max_length=255, blank=True, null=True, deduplication_field=True
|
||||
)
|
||||
pages = fields.IntegerField(blank=True, null=True)
|
||||
physical_format = fields.CharField(
|
||||
max_length=255, choices=FormatChoices, null=True, blank=True
|
||||
|
|
|
@ -1 +1 @@
|
|||
black==21.4b2
|
||||
black==22.1.0
|
||||
|
|
Loading…
Reference in a new issue