From b5ce7a0c259580b8d1343c2d07bbfb0491c1afdf Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 3 Jan 2021 07:48:57 -0800 Subject: [PATCH 1/4] Search on username and localname in user search --- bookwyrm/views.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bookwyrm/views.py b/bookwyrm/views.py index 10137684b..40c2c9dca 100644 --- a/bookwyrm/views.py +++ b/bookwyrm/views.py @@ -5,6 +5,7 @@ from django.contrib.auth.decorators import login_required, permission_required from django.contrib.postgres.search import TrigramSimilarity from django.core.paginator import Paginator from django.db.models import Avg, Q +from django.db.models.functions import Greatest from django.http import HttpResponseNotFound, JsonResponse from django.core.exceptions import PermissionDenied from django.shortcuts import get_object_or_404, redirect @@ -227,7 +228,10 @@ def search(request): # do a local user search user_results = models.User.objects.annotate( - similarity=TrigramSimilarity('username', query), + similarity=Greatest( + TrigramSimilarity('username', query), + TrigramSimilarity('localname', query), + ) ).filter( similarity__gt=0.5, ).order_by('-similarity')[:10] From e54e1f245996737c5ebbd7dc9fb51a365324b974 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 3 Jan 2021 07:57:57 -0800 Subject: [PATCH 2/4] Tests user search --- bookwyrm/tests/test_views.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/bookwyrm/tests/test_views.py b/bookwyrm/tests/test_views.py index 34321e832..69188e2b7 100644 --- a/bookwyrm/tests/test_views.py +++ b/bookwyrm/tests/test_views.py @@ -211,6 +211,19 @@ class Views(TestCase): response.context_data['book_results'][0].title, 'Gideon the Ninth') + def test_search_html_response_users(self): + ''' searches remote connectors ''' + request = self.factory.get('', {'q': 'mouse'}) + with patch('bookwyrm.views.is_api_request') as is_api: + is_api.return_value = False + with patch('bookwyrm.connectors.connector_manager.search'): + response = views.search(request) + self.assertIsInstance(response, TemplateResponse) + self.assertEqual(response.template_name, 'search_results.html') + self.assertEqual( + response.context_data['user_results'][0], self.local_user) + + def test_import_page(self): ''' there are so many views, this just makes sure it LOADS ''' request = self.factory.get('') From 4d4b27e8447463a3992a3cff3456fd78866a5564 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 3 Jan 2021 08:17:00 -0800 Subject: [PATCH 3/4] Fixes replies showing up twice in feed --- bookwyrm/views.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bookwyrm/views.py b/bookwyrm/views.py index b518c4fac..09f727f27 100644 --- a/bookwyrm/views.py +++ b/bookwyrm/views.py @@ -45,7 +45,8 @@ def is_api_request(request): def is_bookworm_request(request): ''' check if the request is coming from another bookworm instance ''' user_agent = request.headers.get('User-Agent') - if user_agent is None or re.search(regex.bookwyrm_user_agent, user_agent) is None: + if user_agent is None or \ + re.search(regex.bookwyrm_user_agent, user_agent) is None: return False return True @@ -180,7 +181,7 @@ def get_activity_feed(user, filter_level, model=models.Status): return activities.filter( Q(user=user) | Q(mention_users=user), privacy='direct' - ) + ).distinct() # never show DMs in the regular feed activities = activities.filter(~Q(privacy='direct')) @@ -195,7 +196,7 @@ def get_activity_feed(user, filter_level, model=models.Status): Q(user__in=following, privacy__in=[ 'public', 'unlisted', 'followers' ]) | Q(mention_users=user) | Q(user=user) - ) + ).distinct() elif filter_level == 'self': activities = activities.filter(user=user, privacy='public') elif filter_level == 'local': @@ -512,7 +513,8 @@ def status_page(request, username, status_id): return HttpResponseNotFound() if is_api_request(request): - return ActivitypubResponse(status.to_activity(pure=not is_bookworm_request(request))) + return ActivitypubResponse( + status.to_activity(pure=not is_bookworm_request(request))) data = { 'title': 'Status by %s' % user.username, From 04eb51863306a10313b1f4c4a417779b106a7765 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 3 Jan 2021 10:03:57 -0800 Subject: [PATCH 4/4] Make the top bar dropdown accessible to NVDA screenreaders plus, it's just better for this to be a ul --- bookwyrm/templates/layout.html | 54 +++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/bookwyrm/templates/layout.html b/bookwyrm/templates/layout.html index ab113ad09..3e1af28c2 100644 --- a/bookwyrm/templates/layout.html +++ b/bookwyrm/templates/layout.html @@ -63,33 +63,45 @@