From 4727eb31e50fa1571c83c4be5e228534b07574a7 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Mon, 26 Jun 2023 11:25:27 +0200 Subject: [PATCH] Nicer search, minor fixes. --- src/catalogue/fields.py | 5 +- .../templates/catalogue/2022/book_box.html | 4 +- .../templates/catalogue/2022/book_list.html | 4 +- .../catalogue/2022/tag_catalogue.html | 2 +- src/search/views.py | 92 +++++++++++++++--- src/wolnelektury/settings/contrib.py | 1 + .../2022/styles/components/_search.scss | 95 +++++++++++++++++++ .../static/2022/styles/local.scss | 5 - .../static/2022/styles/utils/_vars.scss | 5 + src/wolnelektury/static/js/search.js | 13 ++- 10 files changed, 195 insertions(+), 31 deletions(-) diff --git a/src/catalogue/fields.py b/src/catalogue/fields.py index c592c5504..6ae4da3c4 100644 --- a/src/catalogue/fields.py +++ b/src/catalogue/fields.py @@ -372,11 +372,8 @@ class CoverCleanField(CoverField): @staticmethod def transform(wldoc): - if wldoc.book_info.cover_box_position == 'none': - from librarian.cover import WLCover - return WLCover(wldoc.book_info, width=240).output_file() from librarian.covers.marquise import MarquiseCover - return MarquiseCover(wldoc.book_info, width=240).output_file() + return MarquiseCover(wldoc.book_info, width=360).output_file() class CoverThumbField(CoverField): diff --git a/src/catalogue/templates/catalogue/2022/book_box.html b/src/catalogue/templates/catalogue/2022/book_box.html index 4919ba1ba..97c61d936 100644 --- a/src/catalogue/templates/catalogue/2022/book_box.html +++ b/src/catalogue/templates/catalogue/2022/book_box.html @@ -6,7 +6,9 @@ {% if book.is_picture %} {% if book.image_file %} {% thumbnail book.image_file "170x240" crop="center" as im %} - + {% endthumbnail %} {% endif %} {% else %} diff --git a/src/catalogue/templates/catalogue/2022/book_list.html b/src/catalogue/templates/catalogue/2022/book_list.html index 7c6e310a5..1652e7a67 100644 --- a/src/catalogue/templates/catalogue/2022/book_list.html +++ b/src/catalogue/templates/catalogue/2022/book_list.html @@ -17,9 +17,9 @@
{% if main_tag.photo %} - {% thumbnail main_tag.photo '40x40' crop='center' as th %} + {% thumbnail main_tag.photo '40x40' crop='top' as th %}
- {{ main_tag.name }} + {{ main_tag.name }}
{% endthumbnail %} {% endif %} diff --git a/src/catalogue/templates/catalogue/2022/tag_catalogue.html b/src/catalogue/templates/catalogue/2022/tag_catalogue.html index 517562a19..a44e5b20a 100644 --- a/src/catalogue/templates/catalogue/2022/tag_catalogue.html +++ b/src/catalogue/templates/catalogue/2022/tag_catalogue.html @@ -30,7 +30,7 @@ {% for tag in tags %}
  • {% if tag.photo %} - {% thumbnail tag.photo '40x40' crop='center' as thumb %} + {% thumbnail tag.photo '40x40' crop='top' as thumb %} {% endthumbnail %} {% endif %} diff --git a/src/search/views.py b/src/search/views.py index e5ea59837..f7953c315 100644 --- a/src/search/views.py +++ b/src/search/views.py @@ -5,8 +5,11 @@ from django.conf import settings from django.shortcuts import render from django.views.decorators import cache from django.http import HttpResponse, JsonResponse +from sorl.thumbnail import get_thumbnail -from catalogue.models import Book, Tag +import catalogue.models +import infopages.models +import picture.models from .forms import SearchFilters import re import json @@ -37,30 +40,91 @@ def hint(request, mozhint=False, param='term'): if limit < 1: limit = 20 - authors = Tag.objects.filter( - category='author', name_pl__iregex='\m' + prefix).only('name', 'id', 'slug', 'category') - data = [ - { - 'label': author.name, - 'id': author.id, - 'url': author.get_absolute_url(), - } - for author in authors[:limit] - ] + data = [] if len(data) < limit: - for b in Book.objects.filter(findable=True, title__iregex='\m' + prefix)[:limit-len(data)]: + authors = catalogue.models.Tag.objects.filter( + category='author', name_pl__iregex='\m' + prefix).only('name', 'id', 'slug', 'category') + data.extend([ + { + 'type': 'author', + 'label': author.name, + 'url': author.get_absolute_gallery_url() if author.for_pictures else author.get_absolute_url(), + 'img': get_thumbnail(author.photo, '72x72', crop='top').url if author.photo else '', + } + for author in authors[:limit - len(data)] + ]) + if request.user.is_authenticated and len(data) < limit: + tags = catalogue.models.Tag.objects.filter( + category='set', user=request.user, name_pl__iregex='\m' + prefix).only('name', 'id', 'slug', 'category') + data.extend([ + { + 'type': 'set', + 'label': tag.name, + 'url': tag.get_absolute_url(), + } + for tag in tags[:limit - len(data)] + ]) + if len(data) < limit: + tags = catalogue.models.Tag.objects.filter( + category__in=('theme', 'genre', 'epoch', 'kind'), name_pl__iregex='\m' + prefix).only('name', 'id', 'slug', 'category') + data.extend([ + { + 'type': tag.category, + 'label': tag.name, + 'url': tag.get_absolute_gallery_url() if tag.for_pictures else tag.get_absolute_url(), + } + for tag in tags[:limit - len(data)] + ]) + if len(data) < limit: + collections = catalogue.models.Collection.objects.filter( + title_pl__iregex='\m' + prefix).only('title', 'slug') + data.extend([ + { + 'type': 'collection', + 'label': collection.title, + 'url': collection.get_absolute_url(), + } + for collection in collections[:limit - len(data)] + ]) + if len(data) < limit: + for b in catalogue.models.Book.objects.filter(findable=True, title__iregex='\m' + prefix)[:limit-len(data)]: author_str = b.author_unicode() translator = b.translator() if translator: author_str += ' (tłum. ' + translator + ')' data.append( { + 'type': 'book', 'label': b.title, 'author': author_str, - 'id': b.id, - 'url': b.get_absolute_url() + 'url': b.get_absolute_url(), + 'img': get_thumbnail(b.cover_clean, '72x72').url if b.cover_clean else '', } ) + if len(data) < limit: + arts = picture.models.Picture.objects.filter( + title__iregex='\m' + prefix).only('title', 'id', 'slug') # img? + data.extend([ + { + 'type': 'art', + 'label': art.title, + 'author': art.author_unicode(), + 'url': art.get_absolute_url(), + 'img': get_thumbnail(art.image_file, '72x72').url if art.image_file else '', + } + for art in arts[:limit - len(data)] + ]) + if len(data) < limit: + infos = infopages.models.InfoPage.objects.filter( + title_pl__iregex='\m' + prefix).only('title', 'id', 'slug') + data.extend([ + { + 'type': 'info', + 'label': info.title, + 'url': info.get_absolute_url(), + } + for info in infos[:limit - len(data)] + ]) if mozhint: data = [ diff --git a/src/wolnelektury/settings/contrib.py b/src/wolnelektury/settings/contrib.py index d410ddd89..d1c47dfa7 100644 --- a/src/wolnelektury/settings/contrib.py +++ b/src/wolnelektury/settings/contrib.py @@ -4,6 +4,7 @@ HONEYPOT_FIELD_NAME = 'miut' PAGINATION_INVALID_PAGE_RAISES_404 = True THUMBNAIL_QUALITY = 95 +THUMBNAIL_ALTERNATIVE_RESOLUTIONS = [2] MODELTRANSLATION_DEFAULT_LANGUAGE = 'pl' MODELTRANSLATION_PREPOPULATE_LANGUAGE = 'pl' diff --git a/src/wolnelektury/static/2022/styles/components/_search.scss b/src/wolnelektury/static/2022/styles/components/_search.scss index 115101410..3e77e40ce 100644 --- a/src/wolnelektury/static/2022/styles/components/_search.scss +++ b/src/wolnelektury/static/2022/styles/components/_search.scss @@ -140,3 +140,98 @@ } } } + + +.ui-autocomplete { + .ui-menu-item { + &:before { + } + + span { + border-radius: 18px; + padding: 0px 10px; + } + + &.type-info { + &:before { + content: '\1f6c8'; + position: absolute; + left: 0; + width:36px; + line-height: 36px; + text-align: center; + } + } + &.type-theme { + &:before { + content: '☆'; + position: absolute; + left: 0; + width:36px; + line-height: 36px; + text-align: center; + } + } + &.type-genre { + a, a:hover { + span { + color: black; + background: $wl-green; + } + } + } + &.type-epoch { + a, a:hover { + span { + background: $wl-teal; + color: white; + } + } + } + &.type-kind { + a, a:hover { + span { + color: black; + background: $wl-red; + } + } + } + &.type-set { + &:before { + content: ''; + position: absolute; + left: 0; + width:36px; + line-height: 36px; + text-align: center; + font-family: 'wl' !important; + color: $wl-red; + } + } + + a.ui-menu-item-wrapper { + display: flex; + transition: none; + padding: 0; + align-items: center; + + &:hover { + text-decoration: none; + } + + div { + width: 36px; + height: 36px; + display: flex; + align-items: center; + justify-content: center; + margin-right: 5px; + img { + max-height: 36px; + max-width: 36px; + } + } + } + } +} + diff --git a/src/wolnelektury/static/2022/styles/local.scss b/src/wolnelektury/static/2022/styles/local.scss index 7ea03fa3e..f72b99710 100644 --- a/src/wolnelektury/static/2022/styles/local.scss +++ b/src/wolnelektury/static/2022/styles/local.scss @@ -4,11 +4,6 @@ $green: #92BD39; $red: #FF4C54; -.ui-autocomplete a { - display: block; - transition: none; -} - .jp-state-playing .icon-play { &:before { diff --git a/src/wolnelektury/static/2022/styles/utils/_vars.scss b/src/wolnelektury/static/2022/styles/utils/_vars.scss index ac3d0811b..d5f81ccfe 100644 --- a/src/wolnelektury/static/2022/styles/utils/_vars.scss +++ b/src/wolnelektury/static/2022/styles/utils/_vars.scss @@ -20,6 +20,11 @@ $color-dark-primary: #21535F; $color-darker-primary: #083F4D; $color-secondary: #92BD39; +$wl-teal: #007880; +$wl-green: #92BD39; +$wl-red: #FF4C54; + + $color-white: #ffffff; $color-black: #000000; $color-darker: #0e0f0f; diff --git a/src/wolnelektury/static/js/search.js b/src/wolnelektury/static/js/search.js index e3e50b780..536164b50 100644 --- a/src/wolnelektury/static/js/search.js +++ b/src/wolnelektury/static/js/search.js @@ -46,14 +46,19 @@ var __bind = function (self, fn) { render_item_2022: function (ul, item) { var label; - if (item['author']) { + var $label = $("
  • "); + if (item.img) { + $('div', $label).append($('').attr('src', item.img)); + } + if (item.author) { label = '' + item.label + ', ' + item['author']; } else { label = item.label; } - return $("
  • ") - .append(''+label+'') - .appendTo(ul); + $('span', $label).html(label); + $label.addClass('type-' + item.type); + $label.appendTo(ul); + return $label; }, destroy: function() { -- 2.20.1