Merge branch 'main' into suggestions-redis
This commit is contained in:
@ -13,21 +13,16 @@ from bookwyrm.activitypub import ActivitypubResponse
|
||||
from bookwyrm.settings import PAGE_LENGTH, STREAMS
|
||||
from bookwyrm.suggested_users import suggested_users
|
||||
from .helpers import get_user_from_username, privacy_filter
|
||||
from .helpers import is_api_request, is_bookwyrm_request, object_visible_to_user
|
||||
from .helpers import is_api_request, is_bookwyrm_request
|
||||
|
||||
|
||||
# pylint: disable= no-self-use
|
||||
@method_decorator(login_required, name="dispatch")
|
||||
class Feed(View):
|
||||
""" activity stream """
|
||||
"""activity stream"""
|
||||
|
||||
def get(self, request, tab):
|
||||
""" user's homepage with activity feed """
|
||||
try:
|
||||
page = int(request.GET.get("page", 1))
|
||||
except ValueError:
|
||||
page = 1
|
||||
|
||||
"""user's homepage with activity feed"""
|
||||
if not tab in STREAMS:
|
||||
tab = "home"
|
||||
|
||||
@ -40,7 +35,7 @@ class Feed(View):
|
||||
**feed_page_data(request.user),
|
||||
**{
|
||||
"user": request.user,
|
||||
"activities": paginated.page(page),
|
||||
"activities": paginated.get_page(request.GET.get("page")),
|
||||
"suggested_users": suggestions,
|
||||
"tab": tab,
|
||||
"goal_form": forms.GoalForm(),
|
||||
@ -52,15 +47,10 @@ class Feed(View):
|
||||
|
||||
@method_decorator(login_required, name="dispatch")
|
||||
class DirectMessage(View):
|
||||
""" dm view """
|
||||
"""dm view"""
|
||||
|
||||
def get(self, request, username=None):
|
||||
""" like a feed but for dms only """
|
||||
try:
|
||||
page = int(request.GET.get("page", 1))
|
||||
except ValueError:
|
||||
page = 1
|
||||
|
||||
"""like a feed but for dms only"""
|
||||
# remove fancy subclasses of status, keep just good ol' notes
|
||||
queryset = models.Status.objects.filter(
|
||||
review__isnull=True,
|
||||
@ -83,13 +73,12 @@ class DirectMessage(View):
|
||||
).order_by("-published_date")
|
||||
|
||||
paginated = Paginator(activities, PAGE_LENGTH)
|
||||
activity_page = paginated.page(page)
|
||||
data = {
|
||||
**feed_page_data(request.user),
|
||||
**{
|
||||
"user": request.user,
|
||||
"partner": user,
|
||||
"activities": activity_page,
|
||||
"activities": paginated.get_page(request.GET.get("page")),
|
||||
"path": "/direct-messages",
|
||||
},
|
||||
}
|
||||
@ -97,16 +86,16 @@ class DirectMessage(View):
|
||||
|
||||
|
||||
class Status(View):
|
||||
""" get posting """
|
||||
"""get posting"""
|
||||
|
||||
def get(self, request, username, status_id):
|
||||
""" display a particular status (and replies, etc) """
|
||||
"""display a particular status (and replies, etc)"""
|
||||
try:
|
||||
user = get_user_from_username(request.user, username)
|
||||
status = models.Status.objects.select_subclasses().get(
|
||||
id=status_id, deleted=False
|
||||
)
|
||||
except (ValueError, models.Status.DoesNotExist):
|
||||
except (ValueError, models.Status.DoesNotExist, models.User.DoesNotExist):
|
||||
return HttpResponseNotFound()
|
||||
|
||||
# the url should have the poster's username in it
|
||||
@ -114,7 +103,7 @@ class Status(View):
|
||||
return HttpResponseNotFound()
|
||||
|
||||
# make sure the user is authorized to see the status
|
||||
if not object_visible_to_user(request.user, status):
|
||||
if not status.visible_to_user(request.user):
|
||||
return HttpResponseNotFound()
|
||||
|
||||
if is_api_request(request):
|
||||
@ -132,10 +121,10 @@ class Status(View):
|
||||
|
||||
|
||||
class Replies(View):
|
||||
""" replies page (a json view of status) """
|
||||
"""replies page (a json view of status)"""
|
||||
|
||||
def get(self, request, username, status_id):
|
||||
""" ordered collection of replies to a status """
|
||||
"""ordered collection of replies to a status"""
|
||||
# the html view is the same as Status
|
||||
if not is_api_request(request):
|
||||
status_view = Status.as_view()
|
||||
@ -150,7 +139,7 @@ class Replies(View):
|
||||
|
||||
|
||||
def feed_page_data(user):
|
||||
""" info we need for every feed page """
|
||||
"""info we need for every feed page"""
|
||||
if not user.is_authenticated:
|
||||
return {}
|
||||
|
||||
@ -163,7 +152,7 @@ def feed_page_data(user):
|
||||
|
||||
|
||||
def get_suggested_books(user, max_books=5):
|
||||
""" helper to get a user's recent books """
|
||||
"""helper to get a user's recent books"""
|
||||
book_count = 0
|
||||
preset_shelves = [("reading", max_books), ("read", 2), ("to-read", max_books)]
|
||||
suggested_books = []
|
||||
@ -175,7 +164,7 @@ def get_suggested_books(user, max_books=5):
|
||||
)
|
||||
shelf = user.shelf_set.get(identifier=preset)
|
||||
|
||||
shelf_books = shelf.shelfbook_set.order_by("-updated_date").all()[:limit]
|
||||
shelf_books = shelf.shelfbook_set.order_by("-updated_date")[:limit]
|
||||
if not shelf_books:
|
||||
continue
|
||||
shelf_preview = {
|
||||
|
Reference in New Issue
Block a user