Fixed bug where previous searches, and orders were not respected by

paging
This commit is contained in:
Raelon Masters
2020-07-05 13:13:09 -04:00
parent b2a8b1de15
commit 7eec7ae883
4 changed files with 56 additions and 37 deletions

View File

@@ -21,7 +21,7 @@ from interface import views
urlpatterns = [
path("admin/", admin.site.urls),
path("", views.index, name="index"),
path("/<query>", views.index, name="index"),
path("home", views.home, name="index"),
path("sort/<_order>", views.index, name="index"),
path("download/<pk>", views.download, name="download"),
path("favorite/<pk>", views.favorite, name="favorite"),
@@ -29,6 +29,8 @@ urlpatterns = [
path("share/<pk>", views.info, name="info"),
path("prev_page/<bookset>", views.prev_page, name="prev_page"),
path("next_page/<bookset>", views.next_page, name="next_page"),
path("prev_page/<bookset>/<_order>", views.prev_page, name="prev_page"),
path("next_page/<bookset>/<_order>", views.next_page, name="next_page"),
path("search/", views.index, name="search"),
path("search/<query>", views.index, name="search"),
path("search/<query>/<_set>", views.index, name="search"),

View File

@@ -81,10 +81,8 @@ $(document).ready(function(){
window.location.href="/"+valueSelected
});
$('#btn-home').on("click", function(){
console.log('Home Pressed');
_location = $(this).attr('data-location');
$('#_order').val(null);
$('#_search').val(null);
window.location.href=_location;
});
$('#search_string').html("<i> "+$('#_search').val().substr(0,15)+"</i>")
});

View File

@@ -39,7 +39,7 @@
<h1 class="app_hdr" id="hdr_branding">pyShelf {{Version}}</h1>
<div class="hdr_nav" id="hdr_nav_center">
<ul id="tab_nav_menu">
<li class="nav_menu_tab active_tab" id="btn-home" data-location="/?query=0"><i class="fas fa-home"></i>&nbsp;Home</li>
<li class="nav_menu_tab active_tab" id="btn-home" data-location="/home"><i class="fas fa-home"></i>&nbsp;Home</li>
<li class="nav_menu_tab"><i class="fas fa-layer-group"></i>&nbsp;Collections</li>
<li class="nav_menu_tab"><i class="fas fa-star"></i>&nbsp;Favorites</li>
<li class="nav_menu_tab"><i class="fas fa-bug"></i>&nbsp;Bug report</li>
@@ -48,7 +48,7 @@
</div>
<div id="horiz_nav_main">
<div id="horiz_nav_left">
<i class="fas fa-arrow-circle-left nav_icon prev_page" onclick="window.location.href = '/prev_page/{{ Set }}'"></i>
<i class="fas fa-arrow-circle-left nav_icon prev_page" onclick="window.location.href = '/prev_page/{{ Set }}/{{ Order }}'"></i>
&nbsp;sort <i class="fas fa-sort nav_icon"></i>
<select id = "sortlist">
<option valie = "" id="empty-sort"></option>
@@ -62,11 +62,11 @@
<i class="fas fa-sort-alpha-down nav_icon"></i>
<i class="fas fa-sort-alpha-up nav_icon"></i>
<input class="nav_search input_box" type="text" size="40" value="search by Title, Author, Tags, or Collections">
<i class="fas fa-search search_submit search_button" onclick="window.location.href = '/prev_page/{{ Set }}'">search</i>
<i class="fas fa-search search_submit search_button" id="search_string" onclick="window.location.href = '/prev_page/{{ Set }}'"></i>
</div>
<div class="horiz_nav_stats">
<i class="fas fa-book nav_icon"></i>&nbsp;{{ NowShowing }} of {{ BookStats }}&nbsp;
<i class="fas fa-arrow-circle-right nav_icon next_page" onclick="window.location.href = '/next_page/{{ Set }}'"></i>
<i class="fas fa-arrow-circle-right nav_icon next_page" onclick="window.location.href = '/next_page/{{ Set }}/{{ Order }}'"></i>
</div>
</div>
</ul>

View File

@@ -28,6 +28,16 @@ def index(request, query=None, _set=1, _limit=None, _order='title'):
_payload
)
def home(request, query=None, _set=1, _limit=None, _order='title'):
"""
Reset Search Queries & Return Home
"""
_payload = payload(request, query, _set, _limit, _order, reset='1')
return render(
request,
"index.html",
_payload
)
def show_collection(request, _collection, _colset):
try:
_set = int(_colset) + 1
@@ -225,7 +235,6 @@ def menu(which, _set=1, parent=None):
return _collections
elif which == "nav_lvl_0":
navigation_list = Navigation.objects.all()
breakpoint()
return navigation_list
def collections_list():
@@ -235,39 +244,49 @@ def collections_list():
collection_key.append(i.collection)
return json.dumps(list(set(collection_key)))
def payload(request, query, _set, _limit, _order):
def payload(request, query, _set, _limit, _order, **kwargs):
"""
Return formatted data to template
"""
breakpoint()
_set = int(_set)
if _set < 1: _set = 1
if _limit is None: _limit = 20
_set_max = int(_set) * _limit
_set_min = _set_max - _limit
_now_showing = "%s-%s"%(_set_min, _set_max)
if query:
if query != request.session.get('cached_query'):
try:
if kwargs['reset']:
request.session['cached_query'] = query
_results = Books().generic_search(query)
_r, _r_len = \
_results[_set_min:_set_max],\
_results.count()
elif query == request.session.get('cached_query'):
_results = Books().generic_search(query)
_r, _r_len = \
_results.order_by(_order)[_set_min:_set_max],\
_results.count()
else:
try:
query = request.session['cached_query']
_results = Books().generic_search(query)
_r, _r_len = \
_results.order_by(_order)[_set_min:_set_max],\
_results.count()
except KeyError:
if _set < 1: _set = 1
if _limit is None: _limit = 20
_set_max = int(_set) * _limit
_set_min = _set_max - _limit
_now_showing = "%s-%s"%(_set_min, _set_max)
_r, _r_len, _search = book_set(_order, _limit, _set), None, None
except KeyError:
_set = int(_set)
if _set < 1: _set = 1
if _limit is None: _limit = 20
_set_max = int(_set) * _limit
_set_min = _set_max - _limit
_now_showing = "%s-%s"%(_set_min, _set_max)
if query:
if query != request.session.get('cached_query'):
request.session['cached_query'] = query
_results = Books().generic_search(query)
_r, _r_len = \
_results[_set_min:_set_max],\
_results.count()
elif query == request.session.get('cached_query'):
_results = Books().generic_search(query)
_r, _r_len = \
_results.order_by(_order)[_set_min:_set_max],\
_results.count()
else:
try:
query = request.session['cached_query']
if query == None: raise KeyError
_results = Books().generic_search(query)
_r, _r_len = \
_results.order_by(_order)[_set_min:_set_max],\
_results.count()
except KeyError:
_r, _r_len, _search = book_set(_order, _limit, _set), None, None
_bookstats, _collectionstats, _collectionobject = \
Books.objects.all().count, Collections.objects.all().count, \