Skip to content

Commit

Permalink
Goodreads Sync - support half star rating columns
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwidude68 committed Nov 5, 2024
1 parent 047acfe commit 9060637
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
4 changes: 4 additions & 0 deletions goodreads_sync/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Goodreads Sync Change Log

## [1.16.10] - 2024-11-05
### Fixed
- Support half stars in the rating column (if the user has that configured for their rating column). The goodreads rating will still be the rounded down value, but it will prevent the calibre value being rounded down/overwritten in this circumstance.

## [1.16.9] - 2024-10-04
### Fixed
- Better handling of 404 errors from books not found when linking that have an ISBN
Expand Down
2 changes: 1 addition & 1 deletion goodreads_sync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ActionGoodreadsSync(InterfaceActionBase):
description = 'Sync from Calibre with the shelves of your goodreads.com account'
supported_platforms = ['windows', 'osx', 'linux']
author = 'Grant Drake'
version = (1, 16, 9)
version = (1, 16, 10)
minimum_calibre_version = (5, 0, 0)

#: This field defines the GUI plugin class that contains all the code
Expand Down
10 changes: 8 additions & 2 deletions goodreads_sync/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,7 @@ def get_calibre_data_for_book(self, book, calibre_id):
book['calibre_author_sort'] = ''
book['calibre_series'] = ''
book['calibre_rating'] = 0.
book['calibre_rating_allow_half_stars'] = False
book['calibre_date_read'] = UNDEFINED_DATE
book['calibre_review_text'] = ''
book['calibre_reading_progress'] = -1
Expand All @@ -955,20 +956,25 @@ def get_calibre_data_for_book(self, book, calibre_id):
if mi.series:
seridx = fmt_sidx(mi.series_index)
book['calibre_series'] = '%s [%s]' % (mi.series, seridx)
self.get_uploadable_columns(mi, book)
self.get_uploadable_columns(db, mi, book)

if not 'goodreads_id' in book:
goodreads_id = self.id_caches.calibre_to_goodreads_ids().get(calibre_id, '')
book['goodreads_id'] = goodreads_id
return True

def get_uploadable_columns(self, mi, book):
def get_uploadable_columns(self, db, mi, book):
custom_columns = db.field_metadata.custom_field_metadata()
rating_column = cfg.plugin_prefs[cfg.STORE_PLUGIN].get(cfg.KEY_RATING_COLUMN, '')
book['calibre_rating'] = 0
book['calibre_rating_allow_half_stars'] = False
if rating_column:
rating = mi.get(rating_column)
if rating:
book['calibre_rating'] = int(rating)
if rating_column.startswith('#') and rating_column in custom_columns:
rating_custom_column = custom_columns[rating_column]
book['calibre_rating_allow_half_stars'] = rating_custom_column['display'].get('allow_half_stars', False)

date_read_column = cfg.plugin_prefs[cfg.STORE_PLUGIN].get(cfg.KEY_DATE_READ_COLUMN, '')
book['calibre_date_read'] = UNDEFINED_DATE
Expand Down
12 changes: 8 additions & 4 deletions goodreads_sync/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ def __init__(self, parent, reading_progress_column, rating_column=None, date_rea
self.pin_view = None
self.reading_progress_column = reading_progress_column
self.rating_column = rating_column
self.allow_half_star_rating = False
self.date_read_column = date_read_column
self.review_text_column = review_text_column
self.create_context_menu()
Expand Down Expand Up @@ -479,7 +480,7 @@ def populate_table(self, calibre_books):
self.setMinimumColumnWidth(5, 220)
delegate = TextWithLengthDelegate(self, 420) # The status comment is limited to 420 characters.
self.setItemDelegateForColumn(5, delegate)
delegate = RatingDelegate(self)
delegate = RatingDelegate(self, is_half_star=True) if self.allow_half_star_rating else RatingDelegate(self)
self.setItemDelegateForColumn(6, delegate)
self.setMinimumColumnWidth(6, 80)
delegate = DateDelegate(self)
Expand Down Expand Up @@ -517,6 +518,7 @@ def populate_table_row(self, row, calibre_book):
self.setItem(row, 6, RatingTableWidgetItem(0, is_read_only=True))
self.setItem(row, 7, DateTableWidgetItem(None, is_read_only=True, fmt=self.format))
self.setItem(row, 8, NumericTableWidgetItem(''))
self.allow_half_star_rating = calibre_book.get('calibre_rating_allow_half_stars', False)

self.setSortingEnabled(True)
self.blockSignals(False)
Expand Down Expand Up @@ -786,7 +788,7 @@ def action_button_clicked(self):
date_read = None
review_text = None
if upload_rating:
rating = int(calibre_book['calibre_rating']) / 2
rating = calibre_book['calibre_rating'] / 2
if rating:
calibre_book['goodreads_rating'] = rating
if upload_date_read:
Expand Down Expand Up @@ -1411,6 +1413,7 @@ class DoAddRemoveTableWidget(QTableWidget):
def __init__(self, parent, rating_column, date_read_column, review_text_column):
QTableWidget.__init__(self, parent)
self.rating_column, self.date_read_column, self.review_text_column = (rating_column, date_read_column, review_text_column)
self.allow_half_star_rating = False
self.create_context_menu()
self.itemSelectionChanged.connect(self.item_selection_changed)
self.doubleClicked.connect(self.search_for_goodreads_books_click)
Expand Down Expand Up @@ -1451,7 +1454,7 @@ def populate_table(self, calibre_books):
self.setMinimumColumnWidth(1, 120)
self.setMinimumColumnWidth(2, 120)

delegate = RatingDelegate(self)
delegate = RatingDelegate(self, is_half_star=True) if self.allow_half_star_rating else RatingDelegate(self)
self.setItemDelegateForColumn(4, delegate)
self.setMinimumColumnWidth(4, 90)
delegate = DateDelegate(self)
Expand Down Expand Up @@ -1480,6 +1483,7 @@ def populate_table_row(self, row, calibre_book):
self.setItem(row, 5, DateTableWidgetItem(calibre_book['calibre_date_read'],
is_read_only=False, default_to_today=True))
self.setItem(row, 6, QTableWidgetItem(calibre_book['calibre_review_text']))
self.allow_half_star_rating = calibre_book.get('calibre_rating_allow_half_stars', False)

self.setSortingEnabled(True)
self.blockSignals(False)
Expand Down Expand Up @@ -1813,7 +1817,7 @@ def action_button_clicked(self):
date_read = None
review_text = None
if upload_rating:
rating = int(calibre_book['calibre_rating'] / 2)
rating = calibre_book['calibre_rating'] / 2
calibre_book['goodreads_rating'] = rating
if upload_date_read:
date_read = calibre_book['calibre_date_read']
Expand Down

0 comments on commit 9060637

Please sign in to comment.