Skip to content

Commit 9b3242f

Browse files
TomWoodwardmwvolo
andauthored
move books into subkey of block (#1628)
* move books into subkey of block * add snippet * fix syntax errors; add migration * listblock, stream_data response --------- Co-authored-by: Michael Volo <[email protected]>
1 parent 676b4f1 commit 9b3242f

File tree

5 files changed

+837
-5
lines changed

5 files changed

+837
-5
lines changed

books/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def get_book_data(book):
7474
'has_faculty_resources': has_faculty_resources,
7575
'has_student_resources': has_student_resources,
7676
'assignable_book': book.assignable_book,
77+
'promote_snippet': book.promote_snippet.stream_block.get_api_representation(book.promote_snippet),
7778
'promote_tags': [snippet.value.name for snippet in book.promote_snippet],
7879
}
7980
except Exception as e:

pages/custom_blocks.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,13 @@ def get_api_representation(self, value, context=None):
326326
'title': value['title'],
327327
}
328328

329-
class BookListBlock(blocks.StreamBlock):
329+
class BookListBlock(blocks.StructBlock):
330330
books = blocks.PageChooserBlock(page_type=['books.Book'], required=False)
331331

332332
class Meta:
333333
icon = 'placeholder'
334-
label = "Book List"
334+
label = "Books"
335335

336336
def get_api_representation(self, value, context=None):
337-
# value is a StreamValue of blocks, each with .value as a Book page
338-
return [book_data for book in value if (book_data := get_book_data(book.value))]
337+
if value:
338+
return get_book_data(value['books'])

0 commit comments

Comments
 (0)