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
|
|
|
|
|
2021-08-08 01:54:00 +00:00
|
|
|
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"""
|
2021-08-08 01:54:00 +00:00
|
|
|
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)
|
2021-08-08 01:54:00 +00:00
|
|
|
| Q(quotation__isnull=False)
|
|
|
|
| Q(mention_books__isnull=False)
|
|
|
|
)
|
2021-08-07 19:33:45 +00:00
|
|
|
)
|
2021-08-08 01:54:00 +00:00
|
|
|
|
2021-08-07 21:38:19 +00:00
|
|
|
large_activities = Paginator(
|
2021-08-08 01:54:00 +00:00
|
|
|
activities.filter(mention_books__isnull=True)
|
|
|
|
.exclude(content=None, quotation__quote=None)
|
|
|
|
.exclude(content=""),
|
|
|
|
6,
|
2021-08-07 21:38:19 +00:00
|
|
|
)
|
|
|
|
small_activities = Paginator(
|
2021-08-08 01:54:00 +00:00
|
|
|
activities.filter(
|
|
|
|
Q(mention_books__isnull=False) | Q(content=None) | Q(content="")
|
|
|
|
),
|
|
|
|
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)
|