Skip to content

Commit 1a17671

Browse files
committed
centralize book data method
1 parent 8392ea6 commit 1a17671

File tree

2 files changed

+6
-58
lines changed

2 files changed

+6
-58
lines changed

books/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ def get_book_data(book):
7171
'salesforce_name': book.salesforce_name,
7272
'urls': book.book_urls(),
7373
'last_updated_pdf': book.last_updated_pdf,
74+
'created': book.created,
75+
'updated': book.updated,
76+
'publish_date': book.publish_date,
7477
'has_faculty_resources': has_faculty_resources,
7578
'has_student_resources': has_student_resources,
7679
'assignable_book': book.assignable_book,

pages/models.py

Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from api.models import FeatureFlag
1515
from openstax.functions import build_image_url, build_document_url
16-
from books.models import Book, SubjectBooks, BookFacultyResources, BookStudentResources
16+
from books.models import Book, SubjectBooks, BookFacultyResources, BookStudentResources, get_book_data
1717
from webinars.models import Webinar
1818
from news.models import BlogStreamBlock # for use on the ImpactStories
1919

@@ -2960,34 +2960,7 @@ def subjects(self):
29602960
and category.subject_category in book.subject_categories \
29612961
and book.book_state not in ['retired', 'unlisted']:
29622962
book_data = []
2963-
book_data.append({
2964-
'id': book.id,
2965-
'slug': 'books/{}'.format(book.slug),
2966-
'book_state': book.book_state,
2967-
'title': book.title,
2968-
'subjects': book.subjects(),
2969-
'subject_categories': book.subject_categories,
2970-
'k12subject': book.k12subjects(),
2971-
'is_ap': book.is_ap,
2972-
'cover_url': book.cover_url,
2973-
'cover_color': book.cover_color,
2974-
'high_resolution_pdf_url': book.high_resolution_pdf_url,
2975-
'low_resolution_pdf_url': book.low_resolution_pdf_url,
2976-
'ibook_link': book.ibook_link,
2977-
'ibook_link_volume_2': book.ibook_link_volume_2,
2978-
'webview_link': book.webview_link,
2979-
'webview_rex_link': book.webview_rex_link,
2980-
'bookshare_link': book.bookshare_link,
2981-
'kindle_link': book.kindle_link,
2982-
'amazon_coming_soon': book.amazon_coming_soon,
2983-
'amazon_link': book.amazon_link,
2984-
'bookstore_coming_soon': book.bookstore_coming_soon,
2985-
'comp_copy_available': book.comp_copy_available,
2986-
'salesforce_abbreviation': book.salesforce_abbreviation,
2987-
'salesforce_name': book.salesforce_name,
2988-
'urls': book.book_urls(),
2989-
'last_updated_pdf': book.last_updated_pdf,
2990-
})
2963+
book_data.append(get_book_data(book))
29912964
books[book.title] = book_data
29922965
book_list['category_description'] = category.description
29932966
book_list['books'] = books
@@ -3156,35 +3129,7 @@ def books(self):
31563129
if book.k12book_subjects is not None \
31573130
and self.title in k12subjects \
31583131
and book.book_state not in ['retired', 'draft']:
3159-
book_data.append({
3160-
'id': book.id,
3161-
'slug': 'books/{}'.format(book.slug),
3162-
'title': book.title,
3163-
'description': book.description,
3164-
'cover_url': book.cover_url,
3165-
'is_ap': book.is_ap,
3166-
'is_hs': 'High School' in subjects,
3167-
'cover_color': book.cover_color,
3168-
'high_resolution_pdf_url': book.high_resolution_pdf_url,
3169-
'low_resolution_pdf_url': book.low_resolution_pdf_url,
3170-
'ibook_link': book.ibook_link,
3171-
'ibook_link_volume_2': book.ibook_link_volume_2,
3172-
'webview_link': book.webview_link,
3173-
'webview_rex_link': book.webview_rex_link,
3174-
'bookshare_link': book.bookshare_link,
3175-
'kindle_link': book.kindle_link,
3176-
'amazon_coming_soon': book.amazon_coming_soon,
3177-
'amazon_link': book.amazon_link,
3178-
'bookstore_coming_soon': book.bookstore_coming_soon,
3179-
'comp_copy_available': book.comp_copy_available,
3180-
'salesforce_abbreviation': book.salesforce_abbreviation,
3181-
'salesforce_name': book.salesforce_name,
3182-
'urls': book.book_urls(),
3183-
'updated': book.updated,
3184-
'created': book.created,
3185-
'publish_date': book.publish_date,
3186-
'last_updated_pdf': book.last_updated_pdf
3187-
})
3132+
book_data.append(get_book_data(book))
31883133
return book_data
31893134

31903135
def student_resource_headers(self):

0 commit comments

Comments
 (0)