feat: author search
This commit is contained in:
@@ -13,6 +13,8 @@ from epub2go_web.tasks import getEpub
|
|||||||
logger = logging.getLogger(__name__) #TODO configure logging
|
logger = logging.getLogger(__name__) #TODO configure logging
|
||||||
|
|
||||||
books = sorted(get_all_books(), key= lambda b: b.title)# TODO get from pickle
|
books = sorted(get_all_books(), key= lambda b: b.title)# TODO get from pickle
|
||||||
|
books_count = len(books)
|
||||||
|
logger.info('Found %s books', books_count)
|
||||||
gbnetloc = urlparse(allbooks_url).netloc
|
gbnetloc = urlparse(allbooks_url).netloc
|
||||||
|
|
||||||
def index(request: HttpRequest):
|
def index(request: HttpRequest):
|
||||||
@@ -33,14 +35,14 @@ def index(request: HttpRequest):
|
|||||||
return response
|
return response
|
||||||
else: return HttpResponseBadRequest('Input URL invalid.')
|
else: return HttpResponseBadRequest('Input URL invalid.')
|
||||||
elif searchParam:
|
elif searchParam:
|
||||||
localbooks = [book for book in books if searchParam.lower() in book.title.lower()]
|
search = searchParam.lower()
|
||||||
|
localbooks = [book for book in books if search in book.title.lower() or search in book.author.lower()]
|
||||||
|
|
||||||
# paginate items
|
# paginate items
|
||||||
paginationParam = request.GET.get('p', '')
|
paginationParam = request.GET.get('p', '')
|
||||||
try:
|
try:
|
||||||
pageNo = int(paginationParam)
|
pageNo = int(paginationParam)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
logger.error('Failed to cast %s to int', paginationParam)
|
|
||||||
pageNo = 1
|
pageNo = 1
|
||||||
|
|
||||||
pages = Paginator(localbooks, 100)
|
pages = Paginator(localbooks, 100)
|
||||||
@@ -51,7 +53,7 @@ def index(request: HttpRequest):
|
|||||||
'title': 'epub2go',
|
'title': 'epub2go',
|
||||||
'http_host': f'http://{ request.META['HTTP_HOST'] }',
|
'http_host': f'http://{ request.META['HTTP_HOST'] }',
|
||||||
'page': page,
|
'page': page,
|
||||||
'allbooks_count': len(books),
|
'allbooks_count': books_count,
|
||||||
'allbooks_url': allbooks_url,
|
'allbooks_url': allbooks_url,
|
||||||
}
|
}
|
||||||
# return base view
|
# return base view
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<div class="search-container">
|
<div class="search-container">
|
||||||
<search>
|
<search>
|
||||||
<form onsubmit="submitSearch(event)" class="search-bar">
|
<form onsubmit="submitSearch(event)" class="search-bar">
|
||||||
<input type="search" id="searchInput" placeholder="Suche nach Titel" minlength="3">
|
<input type="search" id="searchInput" placeholder="Suchen" minlength="3">
|
||||||
</form>
|
</form>
|
||||||
</search>
|
</search>
|
||||||
<small>Im Moment finden sich hier <a href="{{ allbooks_url }}">{{ allbooks_count }} Bücher.</a> </small>
|
<small>Im Moment finden sich hier <a href="{{ allbooks_url }}">{{ allbooks_count }} Bücher.</a> </small>
|
||||||
|
|||||||
Reference in New Issue
Block a user