forked from mirrors/bookwyrm
Merge pull request #299 from mouse-reeve/federate_covers
Federate covers
This commit is contained in:
commit
1b50e83c95
3 changed files with 36 additions and 18 deletions
|
@ -84,7 +84,7 @@ class Connector(AbstractConnector):
|
|||
if not response.ok:
|
||||
response.raise_for_status()
|
||||
|
||||
image_name = str(uuid4()) + cover_url.split('.')[-1]
|
||||
image_name = str(uuid4()) + '.' + cover_url.split('.')[-1]
|
||||
image_content = ContentFile(response.content)
|
||||
return [image_name, image_content]
|
||||
|
||||
|
|
|
@ -75,6 +75,16 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
|
|||
))
|
||||
return tags
|
||||
|
||||
@property
|
||||
def ap_status_image(self):
|
||||
''' attach a book cover, if relevent '''
|
||||
if hasattr(self, 'book'):
|
||||
return self.book.ap_cover
|
||||
if self.mention_books.first():
|
||||
return self.mention_books.first().ap_cover
|
||||
return None
|
||||
|
||||
|
||||
shared_mappings = [
|
||||
ActivityMapping('url', 'remote_id', lambda x: None),
|
||||
ActivityMapping('id', 'remote_id'),
|
||||
|
@ -100,6 +110,7 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
|
|||
pure_activity_mappings = shared_mappings + [
|
||||
ActivityMapping('name', 'ap_pure_name'),
|
||||
ActivityMapping('content', 'ap_pure_content'),
|
||||
ActivityMapping('attachment', 'ap_status_image'),
|
||||
]
|
||||
|
||||
activity_serializer = activitypub.Note
|
||||
|
|
|
@ -60,23 +60,7 @@ def home_tab(request, tab):
|
|||
except ValueError:
|
||||
page = 1
|
||||
|
||||
max_books = 5
|
||||
book_count = 0
|
||||
preset_shelves = ['reading', 'read', 'to-read']
|
||||
suggested_books = []
|
||||
for preset in preset_shelves:
|
||||
limit = max_books - book_count
|
||||
shelf = request.user.shelf_set.get(identifier=preset)
|
||||
|
||||
shelf_books = shelf.shelfbook_set.order_by(
|
||||
'-updated_date'
|
||||
).all()[:limit]
|
||||
shelf_preview = {
|
||||
'name': shelf.name,
|
||||
'books': [s.book for s in shelf_books]
|
||||
}
|
||||
suggested_books.append(shelf_preview)
|
||||
book_count += len(shelf_preview['books'])
|
||||
suggested_books = get_suggested_books(request.user)
|
||||
|
||||
activities = get_activity_feed(request.user, tab)
|
||||
|
||||
|
@ -100,6 +84,29 @@ def home_tab(request, tab):
|
|||
return TemplateResponse(request, 'feed.html', data)
|
||||
|
||||
|
||||
def get_suggested_books(user, max_books=5):
|
||||
''' helper to get a user's recent books '''
|
||||
book_count = 0
|
||||
preset_shelves = ['reading', 'read', 'to-read']
|
||||
suggested_books = []
|
||||
for preset in preset_shelves:
|
||||
limit = max_books - book_count
|
||||
shelf = user.shelf_set.get(identifier=preset)
|
||||
|
||||
shelf_books = shelf.shelfbook_set.order_by(
|
||||
'-updated_date'
|
||||
).all()[:limit]
|
||||
if not shelf_books:
|
||||
continue
|
||||
shelf_preview = {
|
||||
'name': shelf.name,
|
||||
'books': [s.book for s in shelf_books]
|
||||
}
|
||||
suggested_books.append(shelf_preview)
|
||||
book_count += len(shelf_preview['books'])
|
||||
return suggested_books
|
||||
|
||||
|
||||
def get_activity_feed(user, filter_level, model=models.Status):
|
||||
''' get a filtered queryset of statuses '''
|
||||
# status updates for your follow network
|
||||
|
|
Loading…
Reference in a new issue