Skip to content

Conversation

@akramcodez
Copy link
Contributor

Closes #11336

Changes

Controller (mybooks.py):

  • Accepts the new order_by parameter (either created or finished).
  • Passes sort choice through to the reading log/business logic.
  • Normalizes sort types for backend compatibility.

Database Layer (bookshelves.py):

  • Expands sort logic to support finished asc/desc alongside created.
  • Pads partial dates (year, year+month) for correct sorting.
  • Books without a finish date are ordered last (when sorting descending) or first (when sorting ascending).
  • SQL sorts by: padded finish date → specificity → date added, as outlined in the issue.

UI Template (reading_log.html):

  • Adds four sort options (Date Added: newest/oldest, Date Finished: newest/oldest) for “Already Read” shelf.
  • Highlights the currently active sort choice.
  • Other shelves retain two sort options.

Screen Recoding

books.sort.mov

Stakeholders

@mekarpeles

Copilot AI review requested due to automatic review settings November 1, 2025 06:43
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds the ability to sort the "Already Read" shelf by finish date in addition to the existing date added sort option. Users can now toggle between four sorting options: Date Added (newest/oldest) and Date Finished (newest/oldest).

  • Adds order_by query parameter to support sorting by either 'created' or 'finished'
  • Implements SQL query logic to join with bookshelves_events table to retrieve finish dates
  • Updates the reading log template to show all four sort options for the "Already Read" shelf

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
openlibrary/templates/account/reading_log.html Adds UI controls for Date Finished sorting options (newest/oldest) on the "Already Read" shelf
openlibrary/plugins/upstream/mybooks.py Updates input handling and sort logic to support the new order_by parameter
openlibrary/core/bookshelves.py Expands sort literal types and implements SQL queries for finish date sorting using bookshelves_events
Comments suppressed due to low confidence (1)

openlibrary/core/bookshelves.py:545

  • The event_type parameter is being set unconditionally, but it should only be set when sorting by 'finished'. When sorting by 'created' date, this parameter is not needed and could cause unexpected behavior if the query is reused. Move this assignment inside the if sort.startswith('finished'): block at line 558.
            reading log, so we need to get work IDs and logged info from there, query

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@akramcodez
Copy link
Contributor Author

PTAL @mekarpeles, thanks.

@github-actions github-actions bot added the Needs: Response Issues which require feedback from lead label Nov 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs: Response Issues which require feedback from lead

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add the option to sort read books by the date the book was finished

2 participants