X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/dea27f4e683e78d64d7841489ac1059e6a7d98c9..b361ffcdb3d3869196b46c91635bbb2ac7d4a151:/apps/catalogue/views.py?ds=sidebyside diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index 26821a3af..b69aa4a9c 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -428,11 +428,21 @@ def find_best_matches(query, user=None): raise ValueError("query must have at least two characters") result = tuple(_tags_starting_with(query, user)) + # remove pdcounter stuff + book_titles = set(match.pretty_title().lower() for match in result + if isinstance(match, models.Book)) + authors = set(match.name.lower() for match in result + if isinstance(match, models.Tag) and match.category=='author') + result = tuple(res for res in result if not ( + (isinstance(res, pdcounter_models.BookStub) and res.pretty_title().lower() in book_titles) + or (isinstance(res, pdcounter_models.Author) and res.name.lower() in authors) + )) + exact_matches = tuple(res for res in result if res.name.lower() == query) if exact_matches: return exact_matches else: - return result[:1] + return tuple(result)[:1] def search(request): @@ -641,16 +651,11 @@ def shelf_book_formats(request, shelf): formats['pdf'] = True if book.root_ancestor.epub_file: formats['epub'] = True - if book.odt_file: - formats['odt'] = True if book.txt_file: formats['txt'] = True - if book.mp3_file: - formats['mp3'] = True - if book.ogg_file: - formats['ogg'] = True - if book.daisy_file: - formats['daisy'] = True + for format in ('odt', 'mp3', 'ogg'): + if not formats[format] and book.has_media(format): + formats[format] = True return HttpResponse(LazyEncoder().encode(formats))