@@ -32,6 +32,47 @@ def cleanhtml(raw_html):
32
32
return cleantext
33
33
34
34
35
+ def get_book_data (book ):
36
+ """Return the book data dict for a single Book instance, matching BookIndex.books property."""
37
+ has_faculty_resources = BookFacultyResources .objects .filter (book_faculty_resource = book ).exists ()
38
+ has_student_resources = BookStudentResources .objects .filter (book_student_resource = book ).exists ()
39
+ try :
40
+ return {
41
+ 'id' : book .id ,
42
+ 'cnx_id' : book .cnx_id ,
43
+ 'slug' : f'books/{ book .slug } ' ,
44
+ 'book_state' : book .book_state ,
45
+ 'title' : book .title ,
46
+ 'subjects' : book .subjects (),
47
+ 'is_ap' : book .is_ap ,
48
+ 'cover_url' : book .cover_url ,
49
+ 'cover_color' : book .cover_color ,
50
+ 'high_resolution_pdf_url' : book .high_resolution_pdf_url ,
51
+ 'low_resolution_pdf_url' : book .low_resolution_pdf_url ,
52
+ 'ibook_link' : book .ibook_link ,
53
+ 'ibook_link_volume_2' : book .ibook_link_volume_2 ,
54
+ 'webview_link' : book .webview_link ,
55
+ 'webview_rex_link' : book .webview_rex_link ,
56
+ 'bookshare_link' : book .bookshare_link ,
57
+ 'kindle_link' : book .kindle_link ,
58
+ 'amazon_coming_soon' : book .amazon_coming_soon ,
59
+ 'amazon_link' : book .amazon_link ,
60
+ 'bookstore_coming_soon' : book .bookstore_coming_soon ,
61
+ 'comp_copy_available' : book .comp_copy_available ,
62
+ 'salesforce_abbreviation' : book .salesforce_abbreviation ,
63
+ 'salesforce_name' : book .salesforce_name ,
64
+ 'urls' : book .book_urls (),
65
+ 'last_updated_pdf' : book .last_updated_pdf ,
66
+ 'has_faculty_resources' : has_faculty_resources ,
67
+ 'has_student_resources' : has_student_resources ,
68
+ 'assignable_book' : book .assignable_book ,
69
+ 'promote_tags' : [snippet .value .name for snippet in book .promote_snippet ],
70
+ }
71
+ except Exception as e :
72
+ capture_exception (e )
73
+ return None
74
+
75
+
35
76
class VideoFacultyResource (models .Model ):
36
77
resource_heading = models .CharField (max_length = 255 )
37
78
resource_description = RichTextField (blank = True , null = True )
@@ -1101,42 +1142,9 @@ def books(self):
1101
1142
books = Book .objects .live ().filter (locale = self .locale ).exclude (book_state = 'unlisted' ).order_by ('title' )
1102
1143
book_data = []
1103
1144
for book in books :
1104
- has_faculty_resources = BookFacultyResources .objects .filter (book_faculty_resource = book ).exists ()
1105
- has_student_resources = BookStudentResources .objects .filter (book_student_resource = book ).exists ()
1106
- try :
1107
- book_data .append ({
1108
- 'id' : book .id ,
1109
- 'cnx_id' : book .cnx_id ,
1110
- 'slug' : 'books/{}' .format (book .slug ),
1111
- 'book_state' : book .book_state ,
1112
- 'title' : book .title ,
1113
- 'subjects' : book .subjects (),
1114
- 'is_ap' : book .is_ap ,
1115
- 'cover_url' : book .cover_url ,
1116
- 'cover_color' : book .cover_color ,
1117
- 'high_resolution_pdf_url' : book .high_resolution_pdf_url ,
1118
- 'low_resolution_pdf_url' : book .low_resolution_pdf_url ,
1119
- 'ibook_link' : book .ibook_link ,
1120
- 'ibook_link_volume_2' : book .ibook_link_volume_2 ,
1121
- 'webview_link' : book .webview_link ,
1122
- 'webview_rex_link' : book .webview_rex_link ,
1123
- 'bookshare_link' : book .bookshare_link ,
1124
- 'kindle_link' : book .kindle_link ,
1125
- 'amazon_coming_soon' : book .amazon_coming_soon ,
1126
- 'amazon_link' : book .amazon_link ,
1127
- 'bookstore_coming_soon' : book .bookstore_coming_soon ,
1128
- 'comp_copy_available' : book .comp_copy_available ,
1129
- 'salesforce_abbreviation' : book .salesforce_abbreviation ,
1130
- 'salesforce_name' : book .salesforce_name ,
1131
- 'urls' : book .book_urls (),
1132
- 'last_updated_pdf' : book .last_updated_pdf ,
1133
- 'has_faculty_resources' : has_faculty_resources ,
1134
- 'has_student_resources' : has_student_resources ,
1135
- 'assignable_book' : book .assignable_book ,
1136
- 'promote_tags' : [snippet .value .name for snippet in book .promote_snippet ],
1137
- })
1138
- except Exception as e :
1139
- capture_exception (e )
1145
+ data = get_book_data (book )
1146
+ if data :
1147
+ book_data .append (data )
1140
1148
return book_data
1141
1149
1142
1150
content_panels = Page .content_panels + [
0 commit comments