Nicer search, minor fixes.
authorRadek Czajka <rczajka@rczajka.pl>
Mon, 26 Jun 2023 09:25:27 +0000 (11:25 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Mon, 26 Jun 2023 09:25:27 +0000 (11:25 +0200)
src/catalogue/fields.py
src/catalogue/templates/catalogue/2022/book_box.html
src/catalogue/templates/catalogue/2022/book_list.html
src/catalogue/templates/catalogue/2022/tag_catalogue.html
src/search/views.py
src/wolnelektury/settings/contrib.py
src/wolnelektury/static/2022/styles/components/_search.scss
src/wolnelektury/static/2022/styles/local.scss
src/wolnelektury/static/2022/styles/utils/_vars.scss
src/wolnelektury/static/js/search.js

index c592c55..6ae4da3 100644 (file)
@@ -372,11 +372,8 @@ class CoverCleanField(CoverField):
 
     @staticmethod
     def transform(wldoc):
 
     @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
         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):
 
 
 class CoverThumbField(CoverField):
index 4919ba1..97c61d9 100644 (file)
@@ -6,7 +6,9 @@
       {% if book.is_picture %}
         {% if book.image_file %}
           {% thumbnail book.image_file "170x240" crop="center" as im %}
       {% if book.is_picture %}
         {% if book.image_file %}
           {% thumbnail book.image_file "170x240" crop="center" as im %}
-          <img src="{{ im.url }}" width="{{ im.x }}" height="{{ im.y }}" />
+          <img src="{{ im.url }}"
+               srcset="{{ im.url }} 1x, {{ im.url|resolution:"2x" }} 2x"
+               width="{{ im.x }}" height="{{ im.y }}" />
           {% endthumbnail %}
         {% endif %}
       {% else %}
           {% endthumbnail %}
         {% endif %}
       {% else %}
index 7c6e310..1652e7a 100644 (file)
@@ -17,9 +17,9 @@
   <div class="l-section">
     <div class="l-author__header">
       {% if main_tag.photo %}
   <div class="l-section">
     <div class="l-author__header">
       {% if main_tag.photo %}
-        {% thumbnail main_tag.photo '40x40' crop='center' as th %}
+        {% thumbnail main_tag.photo '40x40' crop='top' as th %}
         <figure>
         <figure>
-          <img src="{{ th.url }}" alt="{{ main_tag.name }}">
+          <img src="{{ th.url }}" alt="{{ main_tag.name }}" srcset="{{ th.url }} 1x, {{ th.url|resolution:"2x" }} 2x">
         </figure>
         {% endthumbnail %}
       {% endif %}
         </figure>
         {% endthumbnail %}
       {% endif %}
index 517562a..a44e5b2 100644 (file)
@@ -30,7 +30,7 @@
       {% for tag in tags %}
         <li>
           {% if tag.photo %}
       {% for tag in tags %}
         <li>
           {% if tag.photo %}
-            {% thumbnail tag.photo '40x40' crop='center' as thumb %}
+            {% thumbnail tag.photo '40x40' crop='top' as thumb %}
             <img src="{{ thumb.url }}" class="c-avatar">
             {% endthumbnail %}
           {% endif %}
             <img src="{{ thumb.url }}" class="c-avatar">
             {% endthumbnail %}
           {% endif %}
index e5ea598..f7953c3 100644 (file)
@@ -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 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
 from .forms import SearchFilters
 import re
 import json
@@ -37,30 +40,91 @@ def hint(request, mozhint=False, param='term'):
         if limit < 1:
             limit = 20
 
         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:
     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(
                 {
             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,
                     '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 = [
 
     if mozhint:
         data = [
index d410ddd..d1c47df 100644 (file)
@@ -4,6 +4,7 @@
 HONEYPOT_FIELD_NAME = 'miut'
 PAGINATION_INVALID_PAGE_RAISES_404 = True
 THUMBNAIL_QUALITY = 95
 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'
 
 MODELTRANSLATION_DEFAULT_LANGUAGE = 'pl'
 MODELTRANSLATION_PREPOPULATE_LANGUAGE = 'pl'
index 1151014..3e77e40 100644 (file)
         }
     }
 }
         }
     }
 }
+
+
+.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;
+                }
+            }
+        }
+    }
+}
+
index 7ea03fa..f72b997 100644 (file)
@@ -4,11 +4,6 @@ $green: #92BD39;
 $red: #FF4C54;
 
 
 $red: #FF4C54;
 
 
-.ui-autocomplete a {
-    display: block;
-    transition: none;
-}
-
 
 .jp-state-playing .icon-play {
   &:before {
 
 .jp-state-playing .icon-play {
   &:before {
index ac3d081..d5f81cc 100644 (file)
@@ -20,6 +20,11 @@ $color-dark-primary:         #21535F;
 $color-darker-primary:         #083F4D;
 $color-secondary:              #92BD39;
 
 $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;
 $color-white:         #ffffff;
 $color-black:         #000000;
 $color-darker:        #0e0f0f;
index e3e50b7..536164b 100644 (file)
@@ -46,14 +46,19 @@ var __bind = function (self, fn) {
 
         render_item_2022: function (ul, item) {
             var label;
 
         render_item_2022: function (ul, item) {
             var label;
-            if (item['author']) {
+            var $label = $("<li><a><div></div><span></span></a></li>");
+            if (item.img) {
+                $('div', $label).append($('<img>').attr('src', item.img));
+            }
+            if (item.author) {
                 label = '<cite>' + item.label + '</cite>, ' + item['author'];
             } else {
                 label = item.label;
             }
                 label = '<cite>' + item.label + '</cite>, ' + item['author'];
             } else {
                 label = item.label;
             }
-            return $("<li></li>")
-            .append('<a href="'+this.options.host+item.url+'">'+label+'</a>')
-            .appendTo(ul);
+            $('span', $label).html(label);
+            $label.addClass('type-' + item.type);
+            $label.appendTo(ul);
+            return $label;
         },
 
         destroy: function() {
         },
 
         destroy: function() {