X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/2864109d874d74c0da1bf8cae4b53edfb3636c01..88fd4555db2f2a3e5a7b4ccc81edb008dc434596:/src/catalogue/views.py diff --git a/src/catalogue/views.py b/src/catalogue/views.py index 98dafc51b..81d0a02b8 100644 --- a/src/catalogue/views.py +++ b/src/catalogue/views.py @@ -108,6 +108,11 @@ def object_list(request, objects, fragments=None, related_tags=None, tags=None, categories = split_tags(*related_tag_lists) objects = list(objects) + + if not objects and len(tags) == 1 and list_type == 'books': + if PictureArea.tagged.with_any(tags).exists() or Picture.tagged.with_any(tags).exists(): + return redirect('tagged_object_list_gallery', '/'.join(tag.url_chunk for tag in tags)) + if len(objects) > 3: best = random.sample(objects, 3) else: @@ -201,10 +206,7 @@ def theme_list(request, tags, list_type): fragments = fragments.filter(Q(book__in=books) | Q(book__ancestor__in=books)) if not fragments and len(tags) == 1 and list_type == 'books': - tag = tags[0] - if tag.category == 'theme' and ( - PictureArea.tagged.with_any([tag]).exists() or - Picture.tagged.with_any([tag]).exists()): + if PictureArea.tagged.with_any(tags).exists() or Picture.tagged.with_any(tags).exists(): return redirect('tagged_object_list_gallery', '/'.join(tag.url_chunk for tag in tags)) return object_list(request, fragments, tags=tags, list_type=list_type, extra={ @@ -352,7 +354,7 @@ def _no_diacritics_regexp(query): def repl(m): l = m.group() - return u"(%s)" % '|'.join(names[l]) + return u"(?:%s)" % '|'.join(names[l]) return re.sub(u'[%s]' % (u''.join(names.keys())), repl, query) @@ -640,13 +642,14 @@ class CustomPDFFormView(AjaxableFormView): @ssi_included def book_mini(request, pk, with_link=True): - book = get_object_or_404(Book, pk=pk) - author_str = ", ".join(tag.name for tag in book.tags.filter(category='author')) + # book = get_object_or_404(Book, pk=pk) + try: + book = Book.objects.only('cover_thumb', 'title', 'language', 'slug').get(pk=pk) + except Book.DoesNotExist: + raise Http404 return render(request, 'catalogue/book_mini_box.html', { 'book': book, - 'author_str': author_str, - 'with_link': with_link, - 'show_lang': book.language_code() != settings.LANGUAGE_CODE, + 'no_link': not with_link, })