mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-04 16:09:54 +00:00
Use elided page range and paginate user and list results
This commit is contained in:
parent
06d1936ac9
commit
48df5076e7
1 changed files with 21 additions and 7 deletions
|
@ -65,14 +65,16 @@ def book_search(request):
|
||||||
|
|
||||||
# try a local-only search
|
# try a local-only search
|
||||||
local_results = search(query, min_confidence=min_confidence)
|
local_results = search(query, min_confidence=min_confidence)
|
||||||
paginated = Paginator(local_results, PAGE_LENGTH).get_page(
|
paginated = Paginator(local_results, PAGE_LENGTH)
|
||||||
request.GET.get("page")
|
page = paginated.get_page(request.GET.get("page"))
|
||||||
)
|
|
||||||
data = {
|
data = {
|
||||||
"query": query,
|
"query": query,
|
||||||
"results": paginated,
|
"results": page,
|
||||||
"type": "book",
|
"type": "book",
|
||||||
"remote": search_remote
|
"remote": search_remote,
|
||||||
|
"page_range": paginated.get_elided_page_range(
|
||||||
|
page.number, on_each_side=2, on_ends=1
|
||||||
|
)
|
||||||
}
|
}
|
||||||
# if a logged in user requested remote results or got no local results, try remote
|
# if a logged in user requested remote results or got no local results, try remote
|
||||||
if request.user.is_authenticated and (not local_results or search_remote):
|
if request.user.is_authenticated and (not local_results or search_remote):
|
||||||
|
@ -96,7 +98,7 @@ def user_search(request):
|
||||||
if re.match(regex.FULL_USERNAME, query):
|
if re.match(regex.FULL_USERNAME, query):
|
||||||
handle_remote_webfinger(query)
|
handle_remote_webfinger(query)
|
||||||
|
|
||||||
data["results"] = (
|
results = (
|
||||||
models.User.viewer_aware_objects(viewer)
|
models.User.viewer_aware_objects(viewer)
|
||||||
.annotate(
|
.annotate(
|
||||||
similarity=Greatest(
|
similarity=Greatest(
|
||||||
|
@ -109,6 +111,12 @@ def user_search(request):
|
||||||
)
|
)
|
||||||
.order_by("-similarity")
|
.order_by("-similarity")
|
||||||
)
|
)
|
||||||
|
paginated = Paginator(results, PAGE_LENGTH)
|
||||||
|
page = paginated.get_page(request.GET.get("page"))
|
||||||
|
data["results"] = page
|
||||||
|
data["page_range"] = paginated.get_elided_page_range(
|
||||||
|
page.number, on_each_side=2, on_ends=1
|
||||||
|
)
|
||||||
return TemplateResponse(request, "search/user.html", data)
|
return TemplateResponse(request, "search/user.html", data)
|
||||||
|
|
||||||
|
|
||||||
|
@ -116,7 +124,7 @@ def list_search(request):
|
||||||
"""any relevent lists?"""
|
"""any relevent lists?"""
|
||||||
query = request.GET.get("q")
|
query = request.GET.get("q")
|
||||||
data = {"query": query, "type": "list"}
|
data = {"query": query, "type": "list"}
|
||||||
data["results"] = (
|
results = (
|
||||||
models.List.privacy_filter(
|
models.List.privacy_filter(
|
||||||
request.user,
|
request.user,
|
||||||
privacy_levels=["public", "followers"],
|
privacy_levels=["public", "followers"],
|
||||||
|
@ -132,6 +140,12 @@ def list_search(request):
|
||||||
)
|
)
|
||||||
.order_by("-similarity")
|
.order_by("-similarity")
|
||||||
)
|
)
|
||||||
|
paginated = Paginator(results, PAGE_LENGTH)
|
||||||
|
page = paginated.get_page(request.GET.get("page"))
|
||||||
|
data["results"] = page
|
||||||
|
data["page_range"] = paginated.get_elided_page_range(
|
||||||
|
page.number, on_each_side=2, on_ends=1
|
||||||
|
)
|
||||||
return TemplateResponse(request, "search/list.html", data)
|
return TemplateResponse(request, "search/list.html", data)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue