Skip to content

move books into subkey of block #1628

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 4 commits into from
May 23, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions books/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def get_book_data(book):
'has_faculty_resources': has_faculty_resources,
'has_student_resources': has_student_resources,
'assignable_book': book.assignable_book,
'promote_snippet': book.promote_snippet,
Copy link
Member Author

@TomWoodward TomWoodward May 21, 2025

Choose a reason for hiding this comment

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

will this naturally come through in the format defined below? its expected to be

   {
        id: number;
        name: string;
        description: string;
        image: string;
    }

Copy link
Member

Choose a reason for hiding this comment

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

hmm, there is a promote snippet on calc 1, which I added to the landing page - it's not even showing up 👀
https://dev.openstax.org/apps/cms/api/v2/pages/562/ (last book)

Copy link
Member

Choose a reason for hiding this comment

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

two books on there are marked as retired. not sure if you want to hide books that are retired like the rest of the site does
i'll leave them there

Copy link
Member Author

Choose a reason for hiding this comment

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

for the snippet, if you look at the calc response directly https://dev.openstax.org/apps/cms/api/v2/pages/74/ it definitely shows it. is in this context is book.promote_snippet maybe not loaded?

Copy link
Member Author

Choose a reason for hiding this comment

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

for retired books, since we're explicitly choosing them i think we should leave them until they're unselected

'promote_tags': [snippet.value.name for snippet in book.promote_snippet],
}
except Exception as e:
Expand Down
3 changes: 2 additions & 1 deletion pages/custom_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,9 @@ class BookListBlock(blocks.StreamBlock):

class Meta:
icon = 'placeholder'
label = "Book List"
label = "Books"

def get_api_representation(self, value, context=None):
# value is a StreamValue of blocks, each with .value as a Book page
if value:
return [book_data for book in value if (book_data := get_book_data(book.value))]
4 changes: 3 additions & 1 deletion pages/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@
('faq', blocks.StreamBlock([
('faq', FAQBlock()),
])),
('book_list', BookListBlock()),
('book_list', blocks.StructBlock([
('books', BookListBlock()),
], label="Book List"),
]

# we have one RootPage, which is the parent of all other pages
Expand Down
Loading