mirror of
https://github.com/kovidgoyal/calibre.git
synced 2026-04-12 04:02:12 -04:00
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>
This commit is contained in:
parent
2a4f8570cd
commit
e7bd5ee3e7
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user