mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-02-02 04:12:20 +00:00
Show dms in the right places
This commit is contained in:
parent
bcdf2ee142
commit
2a5d4b83d8
9 changed files with 42 additions and 46 deletions
|
@ -3,7 +3,7 @@
|
|||
<div class="columns">
|
||||
<div class="column is-narrow">
|
||||
<a href="{{ book.local_path }}">{% include 'snippets/book_cover.html' with book=book size="large" %}</a>
|
||||
{% include 'snippets/stars.html' with rating=ratings|dict_key:book.id %}
|
||||
{% include 'snippets/stars.html' with rating=book|rating:request.user %}
|
||||
</div>
|
||||
<div class="column">
|
||||
<h3 class="title is-5"><a href="/book/{{ book.id }}">{{ book.title }}</a></h3>
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
{% load bookwyrm_tags %}
|
||||
{% if book %}
|
||||
<a href="{{ book.local_path }}">{% include 'snippets/book_cover.html' with book=book %}</a>
|
||||
{% if ratings %}
|
||||
{% include 'snippets/stars.html' with rating=ratings|dict_key:book.id %}
|
||||
{% endif %}
|
||||
{% include 'snippets/stars.html' with rating=book|rating:request.user %}
|
||||
|
||||
<h3 class="title is-6"><a href="/book/{{ book.id }}">{{ book.title }}</a></h3>
|
||||
{% if book.authors %}
|
||||
|
|
|
@ -106,7 +106,7 @@ class ViewsHelpers(TestCase):
|
|||
|
||||
statuses = views.helpers.get_activity_feed(
|
||||
self.local_user,
|
||||
['public', 'unlisted', 'followers'],
|
||||
privacy=['public', 'unlisted', 'followers'],
|
||||
following_only=True,
|
||||
queryset=models.Comment.objects
|
||||
)
|
||||
|
@ -115,7 +115,7 @@ class ViewsHelpers(TestCase):
|
|||
|
||||
statuses = views.helpers.get_activity_feed(
|
||||
self.local_user,
|
||||
['public', 'followers'],
|
||||
privacy=['public', 'followers'],
|
||||
local_only=True
|
||||
)
|
||||
self.assertEqual(len(statuses), 2)
|
||||
|
@ -128,7 +128,7 @@ class ViewsHelpers(TestCase):
|
|||
|
||||
statuses = views.helpers.get_activity_feed(
|
||||
self.local_user,
|
||||
['public', 'followers'],
|
||||
privacy=['public', 'followers'],
|
||||
)
|
||||
self.assertEqual(len(statuses), 3)
|
||||
self.assertEqual(statuses[2], public_status)
|
||||
|
@ -137,7 +137,7 @@ class ViewsHelpers(TestCase):
|
|||
|
||||
statuses = views.helpers.get_activity_feed(
|
||||
self.local_user,
|
||||
['public', 'unlisted', 'followers'],
|
||||
privacy=['public', 'unlisted', 'followers'],
|
||||
following_only=True
|
||||
)
|
||||
self.assertEqual(len(statuses), 2)
|
||||
|
@ -147,7 +147,7 @@ class ViewsHelpers(TestCase):
|
|||
rat.followers.add(self.local_user)
|
||||
statuses = views.helpers.get_activity_feed(
|
||||
self.local_user,
|
||||
['public', 'unlisted', 'followers'],
|
||||
privacy=['public', 'unlisted', 'followers'],
|
||||
following_only=True
|
||||
)
|
||||
self.assertEqual(len(statuses), 5)
|
||||
|
@ -170,18 +170,18 @@ class ViewsHelpers(TestCase):
|
|||
content='blah blah', user=rat)
|
||||
|
||||
statuses = views.helpers.get_activity_feed(
|
||||
self.local_user, ['public'])
|
||||
self.local_user, privacy=['public'])
|
||||
self.assertEqual(len(statuses), 2)
|
||||
|
||||
# block relationship
|
||||
rat.blocks.add(self.local_user)
|
||||
statuses = views.helpers.get_activity_feed(
|
||||
self.local_user, ['public'])
|
||||
self.local_user, privacy=['public'])
|
||||
self.assertEqual(len(statuses), 1)
|
||||
self.assertEqual(statuses[0], public_status)
|
||||
|
||||
statuses = views.helpers.get_activity_feed(
|
||||
rat, ['public'])
|
||||
rat, privacy=['public'])
|
||||
self.assertEqual(len(statuses), 1)
|
||||
self.assertEqual(statuses[0], rat_public)
|
||||
|
||||
|
|
|
@ -50,9 +50,7 @@ class Book(View):
|
|||
)
|
||||
# all reviews for the book
|
||||
reviews = get_activity_feed(
|
||||
request.user,
|
||||
['public', 'unlisted', 'followers', 'direct'],
|
||||
queryset=reviews
|
||||
request.user, queryset=reviews
|
||||
)
|
||||
|
||||
# the reviews to show
|
||||
|
|
|
@ -11,8 +11,7 @@ from django.views import View
|
|||
from bookwyrm import forms, models
|
||||
from bookwyrm.activitypub import ActivitypubResponse
|
||||
from bookwyrm.settings import PAGE_LENGTH
|
||||
from .helpers import get_activity_feed
|
||||
from .helpers import get_user_from_username
|
||||
from .helpers import get_activity_feed, get_user_from_username
|
||||
from .helpers import is_api_request, is_bookwyrm_request, object_visible_to_user
|
||||
|
||||
|
||||
|
@ -28,15 +27,8 @@ class Feed(View):
|
|||
page = 1
|
||||
|
||||
if tab == 'home':
|
||||
activities = get_activity_feed(request.user, following_only=True)
|
||||
# we only want to show private messages if they're related to books
|
||||
activities = activities.exclude(
|
||||
review__isnull=True,
|
||||
comment__isnull=True,
|
||||
quotation__isnull=True,
|
||||
generatednote__isnull=True,
|
||||
privacy='direct'
|
||||
)
|
||||
activities = get_activity_feed(
|
||||
request.user, following_only=True, hide_dms=True)
|
||||
elif tab == 'local':
|
||||
activities = get_activity_feed(
|
||||
request.user, privacy=['public', 'followers'], local_only=True)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
''' helper functions used in various views '''
|
||||
import re
|
||||
from requests import HTTPError
|
||||
from django.core.exceptions import FieldError
|
||||
from django.db.models import Q
|
||||
|
||||
from bookwyrm import activitypub, models
|
||||
|
@ -98,17 +99,23 @@ def privacy_filter(viewer, queryset, privacy_levels=None, following_only=False):
|
|||
|
||||
# exclude direct messages not intended for the user
|
||||
if 'direct' in privacy_levels:
|
||||
queryset = queryset.exclude(
|
||||
~Q(
|
||||
Q(user=viewer) | Q(mention_users=viewer)
|
||||
), privacy='direct'
|
||||
)
|
||||
try:
|
||||
queryset = queryset.exclude(
|
||||
~Q(
|
||||
Q(user=viewer) | Q(mention_users=viewer)
|
||||
), privacy='direct'
|
||||
)
|
||||
except FieldError:
|
||||
queryset = queryset.exclude(
|
||||
~Q(user=viewer), privacy='direct'
|
||||
)
|
||||
|
||||
return queryset
|
||||
|
||||
|
||||
def get_activity_feed(
|
||||
user, privacy=None, local_only=False, following_only=False,
|
||||
queryset=None):
|
||||
queryset=None, hide_dms=False):
|
||||
''' get a filtered queryset of statuses '''
|
||||
if not queryset:
|
||||
queryset = models.Status.objects.select_subclasses()
|
||||
|
@ -120,6 +127,16 @@ def get_activity_feed(
|
|||
queryset = privacy_filter(
|
||||
user, queryset, privacy, following_only=following_only)
|
||||
|
||||
if hide_dms:
|
||||
# dms are direct statuses not related to books
|
||||
queryset = queryset.exclude(
|
||||
review__isnull=True,
|
||||
comment__isnull=True,
|
||||
quotation__isnull=True,
|
||||
generatednote__isnull=True,
|
||||
privacy='direct'
|
||||
)
|
||||
|
||||
# filter for only local status
|
||||
if local_only:
|
||||
queryset = queryset.filter(user__local=True)
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
''' non-interactive pages '''
|
||||
from django.db.models import Avg, Max
|
||||
from django.db.models import Max
|
||||
from django.template.response import TemplateResponse
|
||||
from django.views import View
|
||||
|
||||
from bookwyrm import forms, models
|
||||
from .feed import Feed
|
||||
from .helpers import get_activity_feed
|
||||
|
||||
|
||||
# pylint: disable= no-self-use
|
||||
|
@ -34,6 +33,7 @@ class Discover(View):
|
|||
''' tiled book activity page '''
|
||||
books = models.Edition.objects.filter(
|
||||
review__published_date__isnull=False,
|
||||
review__deleted=False,
|
||||
review__user__local=True,
|
||||
review__privacy__in=['public', 'unlisted'],
|
||||
).exclude(
|
||||
|
@ -42,18 +42,9 @@ class Discover(View):
|
|||
Max('review__published_date')
|
||||
).order_by('-review__published_date__max')[:6]
|
||||
|
||||
ratings = {}
|
||||
for book in books:
|
||||
reviews = models.Review.objects.filter(
|
||||
book__in=book.parent_work.editions.all()
|
||||
)
|
||||
reviews = get_activity_feed(
|
||||
request.user, ['public', 'unlisted'], queryset=reviews)
|
||||
ratings[book.id] = reviews.aggregate(Avg('rating'))['rating__avg']
|
||||
data = {
|
||||
'title': 'Discover',
|
||||
'register_form': forms.RegisterForm(),
|
||||
'books': list(set(books)),
|
||||
'ratings': ratings
|
||||
}
|
||||
return TemplateResponse(request, 'discover/discover.html', data)
|
||||
|
|
|
@ -27,7 +27,7 @@ class RssFeed(Feed):
|
|||
def items(self, obj):
|
||||
''' the user's activity feed '''
|
||||
return get_activity_feed(
|
||||
obj, ['public', 'unlisted'], queryset=obj.status_set)
|
||||
obj, privacy=['public', 'unlisted'], queryset=obj.status_set)
|
||||
|
||||
|
||||
def item_link(self, item):
|
||||
|
|
|
@ -71,8 +71,8 @@ class User(View):
|
|||
# user's posts
|
||||
activities = get_activity_feed(
|
||||
request.user,
|
||||
['public', 'unlisted', 'followers'],
|
||||
queryset=user.status_set
|
||||
queryset=user.status_set.select_subclasses(),
|
||||
hide_dms=True
|
||||
)
|
||||
paginated = Paginator(activities, PAGE_LENGTH)
|
||||
goal = models.AnnualGoal.objects.filter(
|
||||
|
|
Loading…
Reference in a new issue