def get(self, request, tab, filters_applied=False): """user's homepage with activity feed""" tab = [s for s in STREAMS if s["key"] == tab] tab = tab[0] if tab else STREAMS[0] activities = activitystreams.streams[tab["key"]].get_activity_stream( request.user ) filtered_activities = filter_stream_by_status_type( activities, allowed_types=request.user.feed_status_types, ) paginated = Paginator(filtered_activities, PAGE_LENGTH) suggestions = suggested_users.get_suggestions(request.user) data = { **feed_page_data(request.user), **{ "user": request.user, "activities": paginated.get_page(request.GET.get("page")), "suggested_users": suggestions, "tab": tab, "streams": STREAMS, "goal_form": forms.GoalForm(), "feed_status_types_options": FeedFilterChoices, "filters_applied": filters_applied, "path": f"/{tab['key']}", "annual_summary_year": get_annual_summary_year(), }, } return TemplateResponse(request, "feed/feed.html", data)
def test_get_suggestions(self, *_): """load from store""" with patch("bookwyrm.suggested_users.SuggestedUsers.get_store") as mock: mock.return_value = [(self.local_user.id, 7.9)] results = suggested_users.get_suggestions(self.local_user) self.assertEqual(results[0], self.local_user) self.assertEqual(results[0].mutuals, 7)
def get(self, request): """basic profile info""" query = request.GET.get("query") user_results = (models.User.viewer_aware_objects( request.user).annotate(similarity=Greatest( TrigramSimilarity("username", query), TrigramSimilarity("localname", query), )).filter(similarity__gt=0.5, ).order_by("-similarity")[:5]) data = {"no_results": not user_results} if user_results.count() < 5: user_results = list( user_results) + suggested_users.get_suggestions(request.user) data["suggested_users"] = user_results return TemplateResponse(request, "get_started/users.html", data)
def get(self, request, group_id): """basic profile info""" user_query = request.GET.get("user_query") group = get_object_or_404(models.Group, id=group_id) lists = (models.List.privacy_filter( request.user).filter(group=group).order_by("-updated_date")) if not group: return HttpResponseBadRequest() if not group.user == request.user: return HttpResponseBadRequest() user_results = ( models.User.viewer_aware_objects(request.user).exclude( memberships__in=group.memberships.all() ) # don't suggest users who are already members .annotate(similarity=Greatest( TrigramSimilarity("username", user_query), TrigramSimilarity("localname", user_query), )).filter(similarity__gt=0.5, local=True).order_by("-similarity")[:5]) no_results = not user_results if user_results.count() < 5: user_results = list(user_results) + list( suggested_users.get_suggestions(request.user, local=True)) data = { "suggested_users": user_results, "no_results": no_results, "group": group, "lists": lists, "group_form": forms.GroupForm(instance=group, auto_id="group_form_id_%s"), "list_form": forms.ListForm(), "user_query": user_query, "requestor_is_manager": request.user == group.user, } return TemplateResponse(request, "groups/find_users.html", data)
def get(self, request, tab): """user's homepage with activity feed""" tab = [s for s in STREAMS if s["key"] == tab] tab = tab[0] if tab else STREAMS[0] activities = activitystreams.streams[tab["key"]].get_activity_stream( request.user) paginated = Paginator(activities, PAGE_LENGTH) suggestions = suggested_users.get_suggestions(request.user) data = { **feed_page_data(request.user), **{ "user": request.user, "activities": paginated.get_page(request.GET.get("page")), "suggested_users": suggestions, "tab": tab, "streams": STREAMS, "goal_form": forms.GoalForm(), "path": "/%s" % tab["key"], }, } return TemplateResponse(request, "feed/feed.html", data)