mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-27 20:11:14 +00:00
Fixes isbn assignment for goodreads
This commit is contained in:
parent
a9622942cd
commit
fb91c33682
4 changed files with 21 additions and 19 deletions
|
@ -20,20 +20,20 @@ class Importer:
|
|||
encoding = "UTF-8"
|
||||
|
||||
# these are from Goodreads
|
||||
row_mappings_guesses = {
|
||||
"id": ["id", "book id"],
|
||||
"title": ["title"],
|
||||
"authors": ["author", "authors", "primary author"],
|
||||
"isbn_13": ["isbn13", "isbn"],
|
||||
"isbn_10": ["isbn10", "isbn"],
|
||||
"shelf": ["shelf", "exclusive shelf", "read status"],
|
||||
"review_name": ["review name"],
|
||||
"review_body": ["my review", "review"],
|
||||
"rating": ["my rating", "rating", "star rating"],
|
||||
"date_added": ["date added", "entry date", "added"],
|
||||
"date_started": ["date started", "started"],
|
||||
"date_finished": ["date finished", "last date read", "date read", "finished"],
|
||||
}
|
||||
row_mappings_guesses = [
|
||||
("id", ["id", "book id"]),
|
||||
("title", ["title"]),
|
||||
("authors", ["author", "authors", "primary author"]),
|
||||
("isbn_10", ["isbn10", "isbn"]),
|
||||
("isbn_13", ["isbn13", "isbn"]),
|
||||
("shelf", ["shelf", "exclusive shelf", "read status"]),
|
||||
("review_name", ["review name"]),
|
||||
("review_body", ["my review", "review"]),
|
||||
("rating", ["my rating", "rating", "star rating"]),
|
||||
("date_added", ["date added", "entry date", "added"]),
|
||||
("date_started", ["date started", "started"]),
|
||||
("date_finished", ["date finished", "last date read", "date read", "finished"]),
|
||||
]
|
||||
date_fields = ["date_added", "date_started", "date_finished"]
|
||||
shelf_mapping_guesses = {
|
||||
"to-read": ["to-read"],
|
||||
|
@ -60,7 +60,7 @@ class Importer:
|
|||
def create_row_mappings(self, headers):
|
||||
"""guess what the headers mean"""
|
||||
mappings = {}
|
||||
for (key, guesses) in self.row_mappings_guesses.items():
|
||||
for (key, guesses) in self.row_mappings_guesses:
|
||||
value = [h for h in headers if h.lower() in guesses]
|
||||
value = value[0] if len(value) else None
|
||||
if value:
|
||||
|
|
|
@ -12,6 +12,8 @@ from .fields import PrivacyLevels
|
|||
|
||||
def unquote_string(text):
|
||||
"""resolve csv quote weirdness"""
|
||||
if not text:
|
||||
return None
|
||||
match = re.match(r'="([^"]*)"', text)
|
||||
if match:
|
||||
return match.group(1)
|
||||
|
@ -122,7 +124,7 @@ class ImportItem(models.Model):
|
|||
@property
|
||||
def isbn(self):
|
||||
"""pulls out the isbn13 field from the csv line data"""
|
||||
return unquote_string(self.normalized_data["isbn_13"])
|
||||
return unquote_string(self.normalized_data["isbn_13"]) or unquote_string(self.normalized_data["isbn_10"])
|
||||
|
||||
@property
|
||||
def shelf(self):
|
||||
|
|
|
@ -125,7 +125,7 @@
|
|||
{{ item.normalized_data.title }}
|
||||
</td>
|
||||
<td>
|
||||
{{ item.isbn }}
|
||||
{{ item.isbn|default:'' }}
|
||||
</td>
|
||||
<td>
|
||||
{{ item.normalized_data.authors }}
|
||||
|
|
|
@ -53,9 +53,9 @@ class GoodreadsImport(TestCase):
|
|||
self.assertEqual(import_items[0].index, 0)
|
||||
self.assertEqual(import_items[0].data["Book Id"], "42036538")
|
||||
self.assertEqual(
|
||||
import_items[0].normalized_data["isbn_13"], '=""9781250313195"'
|
||||
import_items[0].normalized_data["isbn_13"], '="9781250313195"'
|
||||
)
|
||||
self.assertEqual(import_items[0].normalized_data["isbn_10"], '=""1250313198"')
|
||||
self.assertEqual(import_items[0].normalized_data["isbn_10"], '="1250313198"')
|
||||
|
||||
self.assertEqual(import_items[1].index, 1)
|
||||
self.assertEqual(import_items[1].data["Book Id"], "52691223")
|
||||
|
|
Loading…
Reference in a new issue