def book_page(request, book_id, tab='friends'): ''' info about a book ''' book = models.Book.objects.select_subclasses().get(id=book_id) if is_api_request(request): return JsonResponse(activitypub.get_book(book)) if isinstance(book, models.Work): book = book.default_edition if not book: return HttpResponseNotFound() work = book.parent_work if not work: return HttpResponseNotFound() book_reviews = models.Review.objects.filter( book__in=work.edition_set.all()) if request.user.is_authenticated: user_reviews = book_reviews.filter(user=request.user, ).all() reviews = get_activity_feed(request.user, tab, model=book_reviews) try: # TODO: books can be on multiple shelves shelf = models.Shelf.objects.filter(user=request.user, edition=book).first() except models.Shelf.DoesNotExist: shelf = None user_tags = models.Tag.objects.filter( book=book, user=request.user).values_list('identifier', flat=True) else: tab = 'public' reviews = book_reviews.filter(privacy='public') shelf = None user_reviews = [] user_tags = [] rating = reviews.aggregate(Avg('rating')) tags = models.Tag.objects.filter(book=book).values( 'book', 'name', 'identifier').distinct().all() data = { 'book': book, 'shelf': shelf, 'user_reviews': user_reviews, 'reviews': reviews.distinct(), 'rating': rating['rating__avg'], 'tags': tags, 'user_tags': user_tags, 'review_form': forms.ReviewForm(), 'tag_form': forms.TagForm(), 'feed_tabs': [{ 'id': 'friends', 'display': 'Friends' }, { 'id': 'local', 'display': 'Local' }, { 'id': 'federated', 'display': 'Federated' }], 'active_tab': tab, 'path': '/book/%s' % book_id, 'cover_form': forms.CoverForm(instance=book), 'info_fields': [ { 'name': 'ISBN', 'value': book.isbn_13 }, { 'name': 'OCLC number', 'value': book.oclc_number }, { 'name': 'OpenLibrary ID', 'value': book.openlibrary_key }, { 'name': 'Goodreads ID', 'value': book.goodreads_key }, { 'name': 'Format', 'value': book.physical_format }, { 'name': 'Pages', 'value': book.pages }, ], } return TemplateResponse(request, 'book.html', data)
def activitypub_serialize(self): return activitypub.get_book(self)
def handle_update_book(user, book): ''' broadcast the news about our book ''' book_activity = activitypub.get_book(book) update_activity = activitypub.get_update(user, book_activity) broadcast(user, update_activity)
def handle_update_book(user, book): ''' broadcast the news about our book ''' book_activity = activitypub.get_book(book) update_activity = activitypub.get_update(user, book_activity) recipients = get_recipients(None, 'public') broadcast(user, update_activity, recipients)