-
Notifications
You must be signed in to change notification settings - Fork 16
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
Book on flex #1625
Changes from 3 commits
dde2bf0
2c4c621
77831fa
2518d26
1f046d7
2566859
d281b1a
af03907
2662d83
422b5d6
a887811
8392ea6
1a17671
0c74be7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,47 @@ def cleanhtml(raw_html): | |
| return cleantext | ||
|
|
||
|
|
||
| def get_book_data(book): | ||
| """Return the book data dict for a single Book instance, matching BookIndex.books property.""" | ||
| has_faculty_resources = BookFacultyResources.objects.filter(book_faculty_resource=book).exists() | ||
| has_student_resources = BookStudentResources.objects.filter(book_student_resource=book).exists() | ||
| try: | ||
| return { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 🔥) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 or it might have been subjects... but it was a lot of stuff There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| 'id': book.id, | ||
| 'cnx_id': book.cnx_id, | ||
| 'slug': f'books/{book.slug}', | ||
| 'book_state': book.book_state, | ||
| 'title': book.title, | ||
| 'subjects': book.subjects(), | ||
| 'is_ap': book.is_ap, | ||
| 'cover_url': book.cover_url, | ||
| 'cover_color': book.cover_color, | ||
| 'high_resolution_pdf_url': book.high_resolution_pdf_url, | ||
| 'low_resolution_pdf_url': book.low_resolution_pdf_url, | ||
| 'ibook_link': book.ibook_link, | ||
| 'ibook_link_volume_2': book.ibook_link_volume_2, | ||
| 'webview_link': book.webview_link, | ||
| 'webview_rex_link': book.webview_rex_link, | ||
| 'bookshare_link': book.bookshare_link, | ||
| 'kindle_link': book.kindle_link, | ||
| 'amazon_coming_soon': book.amazon_coming_soon, | ||
| 'amazon_link': book.amazon_link, | ||
| 'bookstore_coming_soon': book.bookstore_coming_soon, | ||
| 'comp_copy_available': book.comp_copy_available, | ||
| 'salesforce_abbreviation': book.salesforce_abbreviation, | ||
| 'salesforce_name': book.salesforce_name, | ||
| 'urls': book.book_urls(), | ||
| 'last_updated_pdf': book.last_updated_pdf, | ||
| 'has_faculty_resources': has_faculty_resources, | ||
| 'has_student_resources': has_student_resources, | ||
| 'assignable_book': book.assignable_book, | ||
| 'promote_tags': [snippet.value.name for snippet in book.promote_snippet], | ||
| } | ||
| except Exception as e: | ||
| capture_exception(e) | ||
| return None | ||
|
|
||
|
|
||
| class VideoFacultyResource(models.Model): | ||
| resource_heading = models.CharField(max_length=255) | ||
| resource_description = RichTextField(blank=True, null=True) | ||
|
|
@@ -1101,42 +1142,9 @@ def books(self): | |
| books = Book.objects.live().filter(locale=self.locale).exclude(book_state='unlisted').order_by('title') | ||
| book_data = [] | ||
| for book in books: | ||
| has_faculty_resources = BookFacultyResources.objects.filter(book_faculty_resource=book).exists() | ||
| has_student_resources = BookStudentResources.objects.filter(book_student_resource=book).exists() | ||
| try: | ||
| book_data.append({ | ||
| 'id': book.id, | ||
| 'cnx_id': book.cnx_id, | ||
| 'slug': 'books/{}'.format(book.slug), | ||
| 'book_state': book.book_state, | ||
| 'title': book.title, | ||
| 'subjects': book.subjects(), | ||
| 'is_ap': book.is_ap, | ||
| 'cover_url': book.cover_url, | ||
| 'cover_color': book.cover_color, | ||
| 'high_resolution_pdf_url': book.high_resolution_pdf_url, | ||
| 'low_resolution_pdf_url': book.low_resolution_pdf_url, | ||
| 'ibook_link': book.ibook_link, | ||
| 'ibook_link_volume_2': book.ibook_link_volume_2, | ||
| 'webview_link': book.webview_link, | ||
| 'webview_rex_link': book.webview_rex_link, | ||
| 'bookshare_link': book.bookshare_link, | ||
| 'kindle_link': book.kindle_link, | ||
| 'amazon_coming_soon': book.amazon_coming_soon, | ||
| 'amazon_link': book.amazon_link, | ||
| 'bookstore_coming_soon': book.bookstore_coming_soon, | ||
| 'comp_copy_available': book.comp_copy_available, | ||
| 'salesforce_abbreviation': book.salesforce_abbreviation, | ||
| 'salesforce_name': book.salesforce_name, | ||
| 'urls': book.book_urls(), | ||
| 'last_updated_pdf': book.last_updated_pdf, | ||
| 'has_faculty_resources': has_faculty_resources, | ||
| 'has_student_resources': has_student_resources, | ||
| 'assignable_book': book.assignable_book, | ||
| 'promote_tags': [snippet.value.name for snippet in book.promote_snippet], | ||
| }) | ||
| except Exception as e: | ||
| capture_exception(e) | ||
| data = get_book_data(book) | ||
| if data: | ||
| book_data.append(data) | ||
| return book_data | ||
|
|
||
| content_panels = Page.content_panels + [ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.