Skip to content

Commit

Permalink
Fix bug in books with pubdate < 1 AD
Browse files Browse the repository at this point in the history
Change models to also include pubyear, an int
Only add pubdate if pubyear > 1
Fixes bug mentioned in issue #58
  • Loading branch information
jd7h committed Oct 19, 2021
1 parent ebf6b7c commit 261a455
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion josephine/booklist/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def __str__(self):
ISBN10 = models.CharField(max_length=10, unique=True, blank=True, null=True)
publisher = models.CharField(max_length=255, blank=True)
pages = models.PositiveIntegerField(blank=True, null=True)
pubdate = models.DateField(blank=True, null=True)
pubdate = models.DateField(blank=True, null=True) # problematic for books from before 1 AD
pubyear = models.IntegerField(blank=True,null=True)
binding = models.CharField(max_length=255, blank=True)
summary = models.CharField(max_length=2000, blank=True)
lang = LanguageField(blank=True, null=True, max_length=10)
Expand Down
4 changes: 3 additions & 1 deletion scripts/goodreads_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def goodreads_record_to_book(record):
if record['Binding'] != '':
book.binding = record['Binding']
if record['Original Publication Year'] != '':
book.pubdate = datetime.datetime(year=int(record['Original Publication Year']), day=1, month=1)
book.pubyear = int(record['Original Publication Year'])
if book.pubyear > 0:
book.pubdate = datetime.datetime(year=int(record['Original Publication Year']), day=1, month=1)
if record['Number of Pages'] != '':
book.pages = int(record['Number of Pages'])
if record['ISBN'] != '':
Expand Down

0 comments on commit 261a455

Please sign in to comment.