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
|
||||
|
||||
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
|
||||
|
||||
def index(request: HttpRequest):
|
||||
@@ -33,14 +35,14 @@ def index(request: HttpRequest):
|
||||
return response
|
||||
else: return HttpResponseBadRequest('Input URL invalid.')
|
||||
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
|
||||
paginationParam = request.GET.get('p', '')
|
||||
try:
|
||||
pageNo = int(paginationParam)
|
||||
except ValueError:
|
||||
logger.error('Failed to cast %s to int', paginationParam)
|
||||
pageNo = 1
|
||||
|
||||
pages = Paginator(localbooks, 100)
|
||||
@@ -51,7 +53,7 @@ def index(request: HttpRequest):
|
||||
'title': 'epub2go',
|
||||
'http_host': f'http://{ request.META['HTTP_HOST'] }',
|
||||
'page': page,
|
||||
'allbooks_count': len(books),
|
||||
'allbooks_count': books_count,
|
||||
'allbooks_url': allbooks_url,
|
||||
}
|
||||
# return base view
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<div class="search-container">
|
||||
<search>
|
||||
<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>
|
||||
</search>
|
||||
<small>Im Moment finden sich hier <a href="{{ allbooks_url }}">{{ allbooks_count }} Bücher.</a> </small>
|
||||
|
||||
Reference in New Issue
Block a user