From e7bd5ee3e72f9bc25a381cba829de05d2d68bdd9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 31 Mar 2026 09:34:54 +0000 Subject: [PATCH] Use rating_to_stars for rating group labels, 'Unrated' for missing/0 values Agent-Logs-Url: https://github.com/kovidgoyal/calibre/sessions/484081a7-d0c9-44da-aabb-4b2e454dc774 Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com> --- src/calibre/gui2/library/annotations.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/library/annotations.py b/src/calibre/gui2/library/annotations.py index 8ffd74d395..466e40878f 100644 --- a/src/calibre/gui2/library/annotations.py +++ b/src/calibre/gui2/library/annotations.py @@ -44,7 +44,7 @@ from qt.core import ( from calibre import prepare_string_for_xml from calibre.constants import builtin_colors_dark, builtin_colors_light, builtin_decorations from calibre.db.backend import FTSQueryError -from calibre.ebooks.metadata import authors_to_sort_string, authors_to_string, fmt_sidx +from calibre.ebooks.metadata import authors_to_sort_string, authors_to_string, fmt_sidx, rating_to_stars from calibre.gui2 import UNDEFINED_QDATETIME, Application, choose_save_file, config, error_dialog, gprefs, is_dark_theme, safe_open_url from calibre.gui2.dialogs.confirm_delete import confirm from calibre.gui2.library.bookshelf_view import all_groupings, iter_all_groups @@ -491,6 +491,15 @@ def get_group_key(result, field, db): # Generic fallback val = get_annotation_value(result, bid, field, db) + if dt == 'rating': + # rating val is an int 0–10 (0 and None both mean unrated) + ival = int(val or 0) + if not ival: + unrated = _('Unrated') + return (0, unrated), unrated + allow_half = fm.get(field, {}).get('display', {}).get('allow_half_stars', False) + label = rating_to_stars(ival, allow_half) + return (ival, label), label if not val: # Use a type-compatible sentinel so that missing-value groups sort # correctly alongside non-missing groups. The non-missing path uses @@ -498,7 +507,7 @@ def get_group_key(result, field, db): # everything else, so the sentinel must match that type. if dt == 'text': missing_sk = primary_sort_key('') - elif dt in ('int', 'rating'): + elif dt == 'int': missing_sk = -1 elif dt == 'float': missing_sk = -1.0