moviewyrm/bookwyrm/views/discover.py

56 lines
1.8 KiB
Python
Raw Normal View History

2021-08-07 18:15:02 +00:00
""" What's up locally """
from django.contrib.auth.decorators import login_required
2021-08-07 19:33:45 +00:00
from django.core.paginator import Paginator
from django.db.models import Q
2021-08-07 18:15:02 +00:00
from django.template.response import TemplateResponse
from django.utils.decorators import method_decorator
from django.views import View
from bookwyrm import activitystreams
2021-08-07 18:15:02 +00:00
# pylint: disable= no-self-use
@method_decorator(login_required, name="dispatch")
class Discover(View):
"""preview of recently reviewed books"""
def get(self, request):
"""tiled book activity page"""
# all activities in the "federated" feed associated with a book
activities = (
activitystreams.streams["local"]
.get_activity_stream(request.user)
.filter(
2021-08-07 19:33:45 +00:00
Q(comment__isnull=False)
| Q(review__isnull=False)
| Q(quotation__isnull=False)
| Q(mention_books__isnull=False)
)
2021-08-07 19:33:45 +00:00
)
2021-08-07 21:38:19 +00:00
large_activities = Paginator(
activities.filter(mention_books__isnull=True)
# exclude statuses with no user-provided content for large panels
.exclude(
Q(Q(content="") | Q(content__isnull=True)) & Q(quotation__isnull=True),
),
6,
2021-08-07 21:38:19 +00:00
)
small_activities = Paginator(
activities.filter(
Q(mention_books__isnull=False)
| Q(
Q(Q(content="") | Q(content__isnull=True))
& Q(quotation__isnull=True),
)
),
4,
2021-08-07 21:38:19 +00:00
)
page = request.GET.get("page")
2021-08-07 18:15:02 +00:00
data = {
2021-08-07 21:38:19 +00:00
"large_activities": large_activities.get_page(page),
"small_activities": small_activities.get_page(page),
2021-08-07 18:15:02 +00:00
}
2021-08-07 19:33:45 +00:00
return TemplateResponse(request, "discover/discover.html", data)