2020-02-22 17:02:03 -05:00
|
|
|
''' views for pages you can go to in the application '''
|
2020-05-04 00:13:43 -04:00
|
|
|
import re
|
|
|
|
|
2020-10-01 15:59:38 -04:00
|
|
|
from django.contrib.auth.decorators import login_required, permission_required
|
2020-10-14 13:04:03 -04:00
|
|
|
from django.contrib.postgres.search import TrigramSimilarity
|
2020-11-11 13:35:34 -05:00
|
|
|
from django.core.paginator import Paginator
|
2021-01-12 13:44:17 -05:00
|
|
|
from django.db.models import Avg, Q
|
2021-01-03 10:48:57 -05:00
|
|
|
from django.db.models.functions import Greatest
|
2020-12-11 19:39:58 -05:00
|
|
|
from django.http import HttpResponseNotFound, JsonResponse
|
2021-01-12 13:19:58 -05:00
|
|
|
from django.shortcuts import get_object_or_404
|
2020-01-25 18:25:19 -05:00
|
|
|
from django.template.response import TemplateResponse
|
2020-03-13 20:57:36 -04:00
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
2020-11-28 11:22:25 -05:00
|
|
|
from django.views.decorators.http import require_GET
|
2020-01-25 01:32:41 -05:00
|
|
|
|
2020-09-21 11:10:37 -04:00
|
|
|
from bookwyrm import outgoing
|
2021-01-02 11:14:28 -05:00
|
|
|
from bookwyrm import forms, models
|
|
|
|
from bookwyrm.activitypub import ActivitypubResponse
|
|
|
|
from bookwyrm.connectors import connector_manager
|
2020-11-11 13:35:34 -05:00
|
|
|
from bookwyrm.settings import PAGE_LENGTH
|
2020-11-01 13:42:48 -05:00
|
|
|
from bookwyrm.utils import regex
|
2020-01-28 14:45:27 -05:00
|
|
|
|
|
|
|
|
2021-01-02 11:14:28 -05:00
|
|
|
def get_edition(book_id):
|
|
|
|
''' look up a book in the db and return an edition '''
|
|
|
|
book = models.Book.objects.select_subclasses().get(id=book_id)
|
|
|
|
if isinstance(book, models.Work):
|
2021-01-02 11:38:27 -05:00
|
|
|
book = book.get_default_edition()
|
2021-01-02 11:14:28 -05:00
|
|
|
return book
|
|
|
|
|
2020-02-22 17:02:03 -05:00
|
|
|
def get_user_from_username(username):
|
|
|
|
''' helper function to resolve a localname or a username to a user '''
|
2020-12-30 16:59:51 -05:00
|
|
|
# raises DoesNotExist if user is now found
|
2020-02-22 17:02:03 -05:00
|
|
|
try:
|
2020-12-30 16:59:51 -05:00
|
|
|
return models.User.objects.get(localname=username)
|
2020-02-22 17:02:03 -05:00
|
|
|
except models.User.DoesNotExist:
|
2020-12-30 16:59:51 -05:00
|
|
|
return models.User.objects.get(username=username)
|
2020-02-22 17:02:03 -05:00
|
|
|
|
|
|
|
|
2020-03-13 20:57:36 -04:00
|
|
|
def is_api_request(request):
|
|
|
|
''' check whether a request is asking for html or data '''
|
|
|
|
return 'json' in request.headers.get('Accept') or \
|
|
|
|
request.path[-5:] == '.json'
|
|
|
|
|
2021-01-03 08:19:03 -05:00
|
|
|
def is_bookworm_request(request):
|
|
|
|
''' check if the request is coming from another bookworm instance '''
|
|
|
|
user_agent = request.headers.get('User-Agent')
|
2021-01-03 11:17:00 -05:00
|
|
|
if user_agent is None or \
|
|
|
|
re.search(regex.bookwyrm_user_agent, user_agent) is None:
|
2021-01-03 08:19:03 -05:00
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
2020-03-13 20:57:36 -04:00
|
|
|
|
2020-03-29 19:05:33 -04:00
|
|
|
def server_error_page(request):
|
|
|
|
''' 500 errors '''
|
2020-12-30 14:42:07 -05:00
|
|
|
return TemplateResponse(
|
|
|
|
request, 'error.html', {'title': 'Oops!'}, status=500)
|
2020-03-29 19:05:33 -04:00
|
|
|
|
|
|
|
|
|
|
|
def not_found_page(request, _):
|
|
|
|
''' 404s '''
|
2020-12-30 14:42:07 -05:00
|
|
|
return TemplateResponse(
|
|
|
|
request, 'notfound.html', {'title': 'Not found'}, status=404)
|
2020-03-29 19:05:33 -04:00
|
|
|
|
|
|
|
|
2021-01-04 22:05:21 -05:00
|
|
|
def get_activity_feed(
|
|
|
|
user, privacy, local_only=False, following_only=False,
|
|
|
|
queryset=models.Status.objects):
|
2020-04-01 19:02:39 -04:00
|
|
|
''' get a filtered queryset of statuses '''
|
2021-01-04 22:05:21 -05:00
|
|
|
privacy = privacy if isinstance(privacy, list) else [privacy]
|
|
|
|
# if we're looking at Status, we need this. We don't if it's Comment
|
|
|
|
if hasattr(queryset, 'select_subclasses'):
|
|
|
|
queryset = queryset.select_subclasses()
|
|
|
|
|
|
|
|
# exclude deleted
|
|
|
|
queryset = queryset.exclude(deleted=True).order_by('-published_date')
|
|
|
|
|
2021-01-04 22:47:22 -05:00
|
|
|
# you can't see followers only or direct messages if you're not logged in
|
|
|
|
if user.is_anonymous:
|
|
|
|
privacy = [p for p in privacy if not p in ['followers', 'direct']]
|
|
|
|
|
2021-01-04 22:05:21 -05:00
|
|
|
# filter to only privided privacy levels
|
|
|
|
queryset = queryset.filter(privacy__in=privacy)
|
|
|
|
|
|
|
|
# only include statuses the user follows
|
|
|
|
if following_only:
|
|
|
|
queryset = queryset.exclude(
|
|
|
|
~Q(# remove everythign except
|
|
|
|
Q(user__in=user.following.all()) | # user follwoing
|
|
|
|
Q(user=user) |# is self
|
|
|
|
Q(mention_users=user)# mentions user
|
|
|
|
),
|
2020-10-29 15:32:37 -04:00
|
|
|
)
|
2021-01-04 22:05:21 -05:00
|
|
|
# exclude followers-only statuses the user doesn't follow
|
|
|
|
elif 'followers' in privacy:
|
|
|
|
queryset = queryset.exclude(
|
|
|
|
~Q(# user isn't following and it isn't their own status
|
|
|
|
Q(user__in=user.following.all()) | Q(user=user)
|
|
|
|
),
|
|
|
|
privacy='followers' # and the status is followers only
|
2020-10-27 18:41:53 -04:00
|
|
|
)
|
2021-01-04 22:05:21 -05:00
|
|
|
|
|
|
|
# exclude direct messages not intended for the user
|
|
|
|
if 'direct' in privacy:
|
|
|
|
queryset = queryset.exclude(
|
|
|
|
~Q(
|
|
|
|
Q(user=user) | Q(mention_users=user)
|
|
|
|
), privacy='direct'
|
2020-10-27 18:41:53 -04:00
|
|
|
)
|
2020-04-01 19:02:39 -04:00
|
|
|
|
2021-01-04 22:05:21 -05:00
|
|
|
# filter for only local status
|
|
|
|
if local_only:
|
|
|
|
queryset = queryset.filter(user__local=True)
|
|
|
|
|
|
|
|
# remove statuses that have boosts in the same queryset
|
2020-12-11 20:39:17 -05:00
|
|
|
try:
|
2021-01-04 22:05:21 -05:00
|
|
|
queryset = queryset.filter(~Q(boosters__in=queryset))
|
2020-12-11 20:39:17 -05:00
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
|
2021-01-04 22:05:21 -05:00
|
|
|
return queryset
|
2020-04-01 19:02:39 -04:00
|
|
|
|
|
|
|
|
2020-11-28 11:22:25 -05:00
|
|
|
@require_GET
|
2020-05-04 00:13:43 -04:00
|
|
|
def search(request):
|
|
|
|
''' that search bar up top '''
|
|
|
|
query = request.GET.get('q')
|
2021-01-07 12:26:05 -05:00
|
|
|
min_confidence = request.GET.get('min_confidence', 0.1)
|
2020-05-04 13:15:41 -04:00
|
|
|
|
|
|
|
if is_api_request(request):
|
2020-10-14 12:19:23 -04:00
|
|
|
# only return local book results via json so we don't cause a cascade
|
2021-01-07 12:26:05 -05:00
|
|
|
book_results = connector_manager.local_search(
|
|
|
|
query, min_confidence=min_confidence)
|
2020-12-30 14:37:26 -05:00
|
|
|
return JsonResponse([r.json() for r in book_results], safe=False)
|
2020-05-04 00:13:43 -04:00
|
|
|
|
2020-11-11 01:06:06 -05:00
|
|
|
# use webfinger for mastodon style account@domain.com username
|
2021-01-06 19:01:13 -05:00
|
|
|
if re.match(r'\B%s' % regex.full_username, query):
|
2020-10-14 12:54:07 -04:00
|
|
|
outgoing.handle_remote_webfinger(query)
|
|
|
|
|
|
|
|
# do a local user search
|
|
|
|
user_results = models.User.objects.annotate(
|
2021-01-03 10:48:57 -05:00
|
|
|
similarity=Greatest(
|
|
|
|
TrigramSimilarity('username', query),
|
|
|
|
TrigramSimilarity('localname', query),
|
|
|
|
)
|
2020-10-14 12:54:07 -04:00
|
|
|
).filter(
|
2020-11-11 01:06:06 -05:00
|
|
|
similarity__gt=0.5,
|
2020-10-14 13:04:03 -04:00
|
|
|
).order_by('-similarity')[:10]
|
2020-10-14 12:19:23 -04:00
|
|
|
|
2021-01-07 12:26:05 -05:00
|
|
|
book_results = connector_manager.search(
|
|
|
|
query, min_confidence=min_confidence)
|
2020-10-14 12:19:23 -04:00
|
|
|
data = {
|
2020-11-02 17:25:16 -05:00
|
|
|
'title': 'Search Results',
|
2020-10-14 12:19:23 -04:00
|
|
|
'book_results': book_results,
|
|
|
|
'user_results': user_results,
|
|
|
|
'query': query,
|
|
|
|
}
|
|
|
|
return TemplateResponse(request, 'search_results.html', data)
|
2020-05-04 00:13:43 -04:00
|
|
|
|
|
|
|
|
2020-11-28 11:22:25 -05:00
|
|
|
@require_GET
|
2020-09-30 19:00:41 -04:00
|
|
|
def book_page(request, book_id):
|
2020-01-27 21:47:54 -05:00
|
|
|
''' info about a book '''
|
2020-11-11 13:50:51 -05:00
|
|
|
try:
|
|
|
|
page = int(request.GET.get('page', 1))
|
|
|
|
except ValueError:
|
|
|
|
page = 1
|
|
|
|
|
2020-11-12 14:40:20 -05:00
|
|
|
try:
|
|
|
|
book = models.Book.objects.select_subclasses().get(id=book_id)
|
|
|
|
except models.Book.DoesNotExist:
|
|
|
|
return HttpResponseNotFound()
|
|
|
|
|
2020-03-27 22:52:05 -04:00
|
|
|
if is_api_request(request):
|
2020-12-30 05:12:04 -05:00
|
|
|
return ActivitypubResponse(book.to_activity())
|
2020-03-27 22:52:05 -04:00
|
|
|
|
2020-03-07 01:56:44 -05:00
|
|
|
if isinstance(book, models.Work):
|
2020-11-28 20:41:57 -05:00
|
|
|
book = book.get_default_edition()
|
2020-04-05 20:00:01 -04:00
|
|
|
if not book:
|
|
|
|
return HttpResponseNotFound()
|
2020-03-30 18:03:21 -04:00
|
|
|
|
|
|
|
work = book.parent_work
|
2020-04-04 16:12:15 -04:00
|
|
|
if not work:
|
|
|
|
return HttpResponseNotFound()
|
2020-03-30 17:12:18 -04:00
|
|
|
|
2020-09-30 19:00:41 -04:00
|
|
|
reviews = models.Review.objects.filter(
|
2020-11-28 20:29:03 -05:00
|
|
|
book__in=work.editions.all(),
|
2020-10-29 15:32:37 -04:00
|
|
|
)
|
2020-11-11 13:50:51 -05:00
|
|
|
# all reviews for the book
|
2021-01-04 22:05:21 -05:00
|
|
|
reviews = get_activity_feed(
|
|
|
|
request.user,
|
|
|
|
['public', 'unlisted', 'followers', 'direct'],
|
|
|
|
queryset=reviews
|
|
|
|
)
|
2020-03-07 01:56:44 -05:00
|
|
|
|
2020-11-11 13:50:51 -05:00
|
|
|
# the reviews to show
|
2021-01-04 20:46:14 -05:00
|
|
|
paginated = Paginator(reviews.exclude(
|
|
|
|
Q(content__isnull=True) | Q(content='')
|
|
|
|
), PAGE_LENGTH)
|
2020-11-11 13:50:51 -05:00
|
|
|
reviews_page = paginated.page(page)
|
|
|
|
|
|
|
|
prev_page = next_page = None
|
|
|
|
if reviews_page.has_next():
|
|
|
|
next_page = '/book/%d/?page=%d' % \
|
|
|
|
(book_id, reviews_page.next_page_number())
|
|
|
|
if reviews_page.has_previous():
|
|
|
|
prev_page = '/book/%s/?page=%d' % \
|
|
|
|
(book_id, reviews_page.previous_page_number())
|
|
|
|
|
2020-12-11 19:39:58 -05:00
|
|
|
user_tags = readthroughs = user_shelves = other_edition_shelves = []
|
2020-03-27 11:05:27 -04:00
|
|
|
if request.user.is_authenticated:
|
2020-11-28 14:00:40 -05:00
|
|
|
user_tags = models.UserTag.objects.filter(
|
2020-03-27 11:05:27 -04:00
|
|
|
book=book, user=request.user
|
2020-11-28 14:00:40 -05:00
|
|
|
).values_list('tag__identifier', flat=True)
|
2020-02-23 17:26:03 -05:00
|
|
|
|
2020-10-29 15:32:37 -04:00
|
|
|
readthroughs = models.ReadThrough.objects.filter(
|
2020-10-29 17:29:31 -04:00
|
|
|
user=request.user,
|
|
|
|
book=book,
|
2020-10-29 15:32:37 -04:00
|
|
|
).order_by('start_date')
|
|
|
|
|
2020-12-11 19:39:58 -05:00
|
|
|
user_shelves = models.ShelfBook.objects.filter(
|
|
|
|
added_by=request.user, book=book
|
|
|
|
)
|
|
|
|
|
|
|
|
other_edition_shelves = models.ShelfBook.objects.filter(
|
|
|
|
~Q(book=book),
|
|
|
|
added_by=request.user,
|
|
|
|
book__parent_work=book.parent_work,
|
|
|
|
)
|
|
|
|
|
2020-01-27 21:47:54 -05:00
|
|
|
data = {
|
2020-11-02 17:25:16 -05:00
|
|
|
'title': book.title,
|
2020-01-27 21:47:54 -05:00
|
|
|
'book': book,
|
2020-11-11 13:50:51 -05:00
|
|
|
'reviews': reviews_page,
|
2021-01-04 20:59:46 -05:00
|
|
|
'review_count': reviews.count(),
|
2021-01-04 20:46:14 -05:00
|
|
|
'ratings': reviews.filter(Q(content__isnull=True) | Q(content='')),
|
2020-12-19 21:54:56 -05:00
|
|
|
'rating': reviews.aggregate(Avg('rating'))['rating__avg'],
|
|
|
|
'tags': models.UserTag.objects.filter(book=book),
|
2020-02-21 01:19:19 -05:00
|
|
|
'user_tags': user_tags,
|
2020-12-11 19:39:58 -05:00
|
|
|
'user_shelves': user_shelves,
|
|
|
|
'other_edition_shelves': other_edition_shelves,
|
2020-10-30 01:38:01 -04:00
|
|
|
'readthroughs': readthroughs,
|
2020-05-03 20:53:14 -04:00
|
|
|
'path': '/book/%s' % book_id,
|
2020-11-11 13:50:51 -05:00
|
|
|
'next': next_page,
|
|
|
|
'prev': prev_page,
|
2020-01-27 21:47:54 -05:00
|
|
|
}
|
|
|
|
return TemplateResponse(request, 'book.html', data)
|
|
|
|
|
|
|
|
|
2020-03-28 18:06:16 -04:00
|
|
|
@login_required
|
2020-10-01 15:59:38 -04:00
|
|
|
@permission_required('bookwyrm.edit_book', raise_exception=True)
|
2020-11-28 11:22:25 -05:00
|
|
|
@require_GET
|
2020-05-03 20:53:14 -04:00
|
|
|
def edit_book_page(request, book_id):
|
2020-03-28 18:06:16 -04:00
|
|
|
''' info about a book '''
|
2021-01-02 11:14:28 -05:00
|
|
|
book = get_edition(book_id)
|
2020-04-04 16:46:10 -04:00
|
|
|
if not book.description:
|
|
|
|
book.description = book.parent_work.description
|
2020-03-28 18:06:16 -04:00
|
|
|
data = {
|
2020-11-02 17:25:16 -05:00
|
|
|
'title': 'Edit Book',
|
2020-03-28 18:06:16 -04:00
|
|
|
'book': book,
|
2020-04-02 11:44:53 -04:00
|
|
|
'form': forms.EditionForm(instance=book)
|
2020-03-28 18:06:16 -04:00
|
|
|
}
|
|
|
|
return TemplateResponse(request, 'edit_book.html', data)
|
|
|
|
|
|
|
|
|
2020-12-22 12:26:40 -05:00
|
|
|
@login_required
|
|
|
|
@permission_required('bookwyrm.edit_book', raise_exception=True)
|
|
|
|
@require_GET
|
|
|
|
def edit_author_page(request, author_id):
|
|
|
|
''' info about a book '''
|
|
|
|
author = get_object_or_404(models.Author, id=author_id)
|
|
|
|
data = {
|
|
|
|
'title': 'Edit Author',
|
|
|
|
'author': author,
|
|
|
|
'form': forms.AuthorForm(instance=author)
|
|
|
|
}
|
|
|
|
return TemplateResponse(request, 'edit_author.html', data)
|
|
|
|
|
|
|
|
|
2020-11-28 11:22:25 -05:00
|
|
|
@require_GET
|
2020-11-04 15:55:00 -05:00
|
|
|
def editions_page(request, book_id):
|
2020-03-30 18:03:21 -04:00
|
|
|
''' list of editions of a book '''
|
2020-11-11 01:06:06 -05:00
|
|
|
work = get_object_or_404(models.Work, id=book_id)
|
2020-11-04 15:55:00 -05:00
|
|
|
|
|
|
|
if is_api_request(request):
|
2020-12-30 05:12:04 -05:00
|
|
|
return ActivitypubResponse(work.to_edition_list(**request.GET))
|
2020-11-04 15:55:00 -05:00
|
|
|
|
2020-03-30 18:03:21 -04:00
|
|
|
data = {
|
2020-11-02 17:25:16 -05:00
|
|
|
'title': 'Editions of %s' % work.title,
|
2021-01-11 13:25:34 -05:00
|
|
|
'editions': work.editions.order_by('-edition_rank').all(),
|
2020-03-30 18:03:21 -04:00
|
|
|
'work': work,
|
|
|
|
}
|
|
|
|
return TemplateResponse(request, 'editions.html', data)
|
|
|
|
|
|
|
|
|
2020-11-28 11:22:25 -05:00
|
|
|
@require_GET
|
2020-05-03 20:53:14 -04:00
|
|
|
def author_page(request, author_id):
|
2020-02-11 01:32:03 -05:00
|
|
|
''' landing page for an author '''
|
2020-11-11 01:06:06 -05:00
|
|
|
author = get_object_or_404(models.Author, id=author_id)
|
2020-02-11 01:32:03 -05:00
|
|
|
|
2020-05-09 15:09:40 -04:00
|
|
|
if is_api_request(request):
|
2020-12-30 05:12:04 -05:00
|
|
|
return ActivitypubResponse(author.to_activity())
|
2020-05-09 15:09:40 -04:00
|
|
|
|
2020-12-20 14:51:17 -05:00
|
|
|
books = models.Work.objects.filter(
|
|
|
|
Q(authors=author) | Q(editions__authors=author)).distinct()
|
2020-02-11 01:32:03 -05:00
|
|
|
data = {
|
2020-11-02 17:25:16 -05:00
|
|
|
'title': author.name,
|
2020-02-11 01:32:03 -05:00
|
|
|
'author': author,
|
2020-11-28 20:41:57 -05:00
|
|
|
'books': [b.get_default_edition() for b in books],
|
2020-02-11 01:32:03 -05:00
|
|
|
}
|
|
|
|
return TemplateResponse(request, 'author.html', data)
|
|
|
|
|
|
|
|
|
2020-11-28 11:22:25 -05:00
|
|
|
@require_GET
|
2020-02-21 12:10:27 -05:00
|
|
|
def tag_page(request, tag_id):
|
|
|
|
''' books related to a tag '''
|
2020-02-21 12:15:20 -05:00
|
|
|
tag_obj = models.Tag.objects.filter(identifier=tag_id).first()
|
2020-09-17 16:02:52 -04:00
|
|
|
if not tag_obj:
|
|
|
|
return HttpResponseNotFound()
|
|
|
|
|
|
|
|
if is_api_request(request):
|
2020-12-30 05:12:04 -05:00
|
|
|
return ActivitypubResponse(tag_obj.to_activity(**request.GET))
|
2020-09-17 16:02:52 -04:00
|
|
|
|
2020-11-28 14:00:40 -05:00
|
|
|
books = models.Edition.objects.filter(
|
|
|
|
usertag__tag__identifier=tag_id
|
|
|
|
).distinct()
|
2020-02-21 12:10:27 -05:00
|
|
|
data = {
|
2020-11-02 17:25:16 -05:00
|
|
|
'title': tag_obj.name,
|
2020-02-21 12:10:27 -05:00
|
|
|
'books': books,
|
2020-02-21 12:15:20 -05:00
|
|
|
'tag': tag_obj,
|
2020-02-21 12:10:27 -05:00
|
|
|
}
|
|
|
|
return TemplateResponse(request, 'tag.html', data)
|
|
|
|
|
|
|
|
|
2020-11-11 13:14:04 -05:00
|
|
|
@csrf_exempt
|
2020-11-28 11:22:25 -05:00
|
|
|
@require_GET
|
2020-11-11 13:14:04 -05:00
|
|
|
def user_shelves_page(request, username):
|
|
|
|
''' list of followers '''
|
|
|
|
return shelf_page(request, username, None)
|
|
|
|
|
|
|
|
|
2020-11-28 11:22:25 -05:00
|
|
|
@require_GET
|
2020-02-21 19:03:05 -05:00
|
|
|
def shelf_page(request, username, shelf_identifier):
|
|
|
|
''' display a shelf '''
|
|
|
|
try:
|
|
|
|
user = get_user_from_username(username)
|
|
|
|
except models.User.DoesNotExist:
|
|
|
|
return HttpResponseNotFound()
|
|
|
|
|
2020-11-10 17:52:04 -05:00
|
|
|
if shelf_identifier:
|
|
|
|
shelf = user.shelf_set.get(identifier=shelf_identifier)
|
|
|
|
else:
|
|
|
|
shelf = user.shelf_set.first()
|
|
|
|
|
2020-11-10 19:43:52 -05:00
|
|
|
is_self = request.user == user
|
|
|
|
|
|
|
|
shelves = user.shelf_set
|
|
|
|
if not is_self:
|
|
|
|
follower = user.followers.filter(id=request.user.id).exists()
|
|
|
|
# make sure the user has permission to view the shelf
|
|
|
|
if shelf.privacy == 'direct' or \
|
|
|
|
(shelf.privacy == 'followers' and not follower):
|
|
|
|
return HttpResponseNotFound()
|
|
|
|
|
|
|
|
# only show other shelves that should be visible
|
|
|
|
if follower:
|
|
|
|
shelves = shelves.filter(privacy__in=['public', 'followers'])
|
|
|
|
else:
|
|
|
|
shelves = shelves.filter(privacy='public')
|
|
|
|
|
|
|
|
|
2020-03-27 22:52:05 -04:00
|
|
|
if is_api_request(request):
|
2020-12-30 05:12:04 -05:00
|
|
|
return ActivitypubResponse(shelf.to_activity(**request.GET))
|
2020-03-27 22:52:05 -04:00
|
|
|
|
2020-12-30 19:07:29 -05:00
|
|
|
books = models.ShelfBook.objects.filter(
|
|
|
|
added_by=user, shelf=shelf
|
|
|
|
).order_by('-updated_date').all()
|
|
|
|
|
2020-11-10 17:07:12 -05:00
|
|
|
data = {
|
2020-12-19 21:54:56 -05:00
|
|
|
'title': '%s\'s %s shelf' % (user.display_name, shelf.name),
|
2020-11-10 17:07:12 -05:00
|
|
|
'user': user,
|
2020-11-10 19:43:52 -05:00
|
|
|
'is_self': is_self,
|
|
|
|
'shelves': shelves.all(),
|
2020-11-10 17:52:04 -05:00
|
|
|
'shelf': shelf,
|
2020-12-30 19:07:29 -05:00
|
|
|
'books': [b.book for b in books],
|
2020-11-10 17:07:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return TemplateResponse(request, 'shelf.html', data)
|