Skip to content

Book on flex #1625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
May 14, 2025
Merged

Book on flex #1625

merged 14 commits into from
May 14, 2025

Conversation

mwvolo
Copy link
Member

@mwvolo mwvolo commented May 8, 2025

@mwvolo mwvolo requested a review from Copilot May 8, 2025 05:34
Copilot

This comment was marked as outdated.

Co-authored-by: Copilot <[email protected]>
@mwvolo mwvolo requested a review from Copilot May 8, 2025 05:36
Copy link
Contributor

@Copilot 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 introduces a new BookListBlock to support the display of book lists on pages and refactors how book data is retrieved in the Book model. Key changes include:

  • Importing and adding BookListBlock in pages/models.py for new block functionality.
  • Defining the BookListBlock in pages/custom_blocks.py that leverages a new get_book_data() helper.
  • Refactoring the book data aggregation in books/models.py to use get_book_data(), along with minor updates to the codecov ignore rules.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

File Description
pages/models.py Added BookListBlock to the existing block imports and stream block mappings.
pages/custom_blocks.py Defined the new BookListBlock with a get_api_representation method using get_book_data.
codecov.yml Updated ignore rules to include additional files and paths.
books/models.py Added get_book_data helper and refactored the book aggregation loop to use it.

@@ -0,0 +1,412 @@
# Generated by Django 5.0.14 on 2025-05-08 05:14
Copy link
Member Author

Choose a reason for hiding this comment

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

this is generated, focus on the models.py file for actual structure changes

has_faculty_resources = BookFacultyResources.objects.filter(book_faculty_resource=book).exists()
has_student_resources = BookStudentResources.objects.filter(book_student_resource=book).exists()
try:
return {
Copy link
Member Author

Choose a reason for hiding this comment

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

this is what's returned on the current subjects page - let me know if you need other fields (or don't need them anymore 🔥)

Copy link
Contributor

Choose a reason for hiding this comment

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

For the book tiles, the FE only needs id, cover_url, title, and slug. It pulls the rest of the details from the main book query (which is used for the subjects page).
Book tiles are currently generated from the book lists included in the specific-subjects page, so that's the model of list to use. The query for that is

`pages/${slug}-books?type=pages.Subject`

Copy link
Member

Choose a reason for hiding this comment

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

@RoyEJohnson it doesn't make a separate query for every book tile does it?

Copy link
Member Author

@mwvolo mwvolo May 8, 2025

Choose a reason for hiding this comment

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

pretty sure it does, the console log was spitting out a constant stream of
Can't load Microbiology
Can't load A&P
...

or it might have been subjects... but it was a lot of stuff
i bet it is subjects, considering the endpoint being called

Copy link
Member

Choose a reason for hiding this comment

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

Ok well id rather include extra data and have the option of changing it to like... Not do a separate query per tile if that's what it does

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not a separate query to the CMS for each book. The main subjects query is pulled once, and is searched for the id of whatever book we're looking for.

Copy link
Member

Choose a reason for hiding this comment

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

But will that work if we're searching for arbitrary books and we're not in the context of a particular subject? The API endpoint that you quoted before looked like it needed to be about a particular subject?

Copy link
Member Author

@mwvolo mwvolo May 9, 2025

Choose a reason for hiding this comment

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

here's a test page with the book block, it has nothing to do with subject (beyond it returning in the response), it's just returning book metadata
https://dev.openstax.org/apps/cms/api/v2/pages/562/
https://dev.openstax.org/admin/pages/562/edit/

@mwvolo mwvolo requested review from TomWoodward and RoyEJohnson May 8, 2025 05:39
mwvolo and others added 2 commits May 7, 2025 23:40
Co-authored-by: Copilot <[email protected]>
Copy link
Member

@TomWoodward TomWoodward left a comment

Choose a reason for hiding this comment

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

looks good to me, but where does the data come from for the new subjects page and other places that use the book data, could those also be updated to use the get_book_data function? (i see that you only updated the deprecated one)

@mwvolo
Copy link
Member Author

mwvolo commented May 8, 2025

good catch, i didn't realize that new page was in the pages model

@mwvolo
Copy link
Member Author

mwvolo commented May 8, 2025

well, it sounded like a good idea to abstract out, but completely broke the subjects pages
given the time crunch on this, i'll probably keep existing structure for the subjects book list

@mwvolo
Copy link
Member Author

mwvolo commented May 14, 2025

I am going to merge this without consolidating the book lists. I will add a card for me to look at this in the future, but something unusual is happening with how books are fetched on subjects - and I've spent too much time on this already.

@mwvolo mwvolo merged commit 676b4f1 into main May 14, 2025
6 of 7 checks passed
@mwvolo mwvolo deleted the book-on-flex branch May 14, 2025 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants