[books] Fix looking up comic by original title
This commit is contained in:
@ -21,7 +21,8 @@ class BookAdmin(admin.ModelAdmin):
|
||||
date_hierarchy = "created"
|
||||
list_display = (
|
||||
"title",
|
||||
"subtitle",
|
||||
"author",
|
||||
"issue_or_volume",
|
||||
"isbn_13",
|
||||
"first_publish_year",
|
||||
"pages",
|
||||
@ -32,6 +33,9 @@ class BookAdmin(admin.ModelAdmin):
|
||||
ScrobbleInline,
|
||||
]
|
||||
|
||||
def issue_or_volume(self, obj):
|
||||
return obj.issue_number or obj.volume_number
|
||||
|
||||
|
||||
@admin.register(Paper)
|
||||
class BookAdmin(admin.ModelAdmin):
|
||||
|
||||
@ -197,9 +197,8 @@ class Book(LongPlayScrobblableMixin):
|
||||
@classmethod
|
||||
def get_from_comicvine(cls, title: str, overwrite: bool = False, force_new: bool =False) -> "Book":
|
||||
book, created = cls.objects.get_or_create(title=title)
|
||||
if not created and not overwrite and not force_new:
|
||||
book, created = cls.objects.get_or_create(original_title=title)
|
||||
logger.info("Found comic by original title, use force_new=True to override")
|
||||
|
||||
if not created:
|
||||
return book
|
||||
|
||||
book_dict = lookup_comic_from_comicvine(title)
|
||||
@ -244,7 +243,7 @@ class Book(LongPlayScrobblableMixin):
|
||||
like to batch create, use commit=False and you'll get an unsaved but enriched
|
||||
instance back which you can then save at your convenience."""
|
||||
# TODO use either a Google Books id identifier or author name like for tracks
|
||||
book, created = cls.objects.get_or_create(title=title)
|
||||
book, created = cls.objects.get_or_create(original_title=title)
|
||||
if not created:
|
||||
logger.info(
|
||||
"Found exact match for book by title", extra={"title": title}
|
||||
@ -258,7 +257,7 @@ class Book(LongPlayScrobblableMixin):
|
||||
return book
|
||||
|
||||
book_dict = lookup_book_from_google(title)
|
||||
if not book_dict or book_dict.get("isbn_10"):
|
||||
if not book_dict or not book_dict.get("isbn_10"):
|
||||
book_dict = lookup_comic_from_comicvine(title)
|
||||
|
||||
author_list = []
|
||||
|
||||
@ -227,14 +227,12 @@ def lookup_comic_from_comicvine(title: str) -> dict:
|
||||
for r in raw_results
|
||||
if r.get("resource_type") == resource_type
|
||||
]
|
||||
print(results)
|
||||
if not results:
|
||||
logger.warning("No comic found on ComicVine")
|
||||
return {}
|
||||
|
||||
found_result = None
|
||||
for result in results:
|
||||
print("checking ", result.get("issue_number"), " to ", str(issue_number))
|
||||
if result.get("issue_number") == str(issue_number):
|
||||
found_result = result
|
||||
break
|
||||
@ -264,6 +262,9 @@ def lookup_comic_from_comicvine(title: str) -> dict:
|
||||
"cover_url": found_result.get("image").get("original_url"),
|
||||
"comicvine_id": found_result.get("id"),
|
||||
"comicvine_data": found_result,
|
||||
"summary": found_result.get("description"),
|
||||
"publish_date": found_result.get("cover_date"),
|
||||
"first_publish_year": found_result.get("store_date").year,
|
||||
}
|
||||
|
||||
return data_dict
|
||||
|
||||
Reference in New Issue
Block a user