From 0e241bee3f90eedd9bc2d339fdc51ce0bec71c72 Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Fri, 2 Nov 2012 13:23:30 +0100 Subject: [PATCH 01/16] Show translator in results Filter tags duplicated by PD --- .../templates/catalogue/search_multiple_hits.html | 13 +++++++++++++ apps/search/index.py | 13 +++++++++---- apps/search/views.py | 14 ++++++++++---- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/apps/catalogue/templates/catalogue/search_multiple_hits.html b/apps/catalogue/templates/catalogue/search_multiple_hits.html index 70988f395..37243023d 100644 --- a/apps/catalogue/templates/catalogue/search_multiple_hits.html +++ b/apps/catalogue/templates/catalogue/search_multiple_hits.html @@ -61,6 +61,19 @@ {% endif %} + {% if results.translator %} +
+
+

{% trans "Results by translators" %}

+
+
+
+
    + {% for translator in results.translator %}
  1. {% book_short translator.book %}
  2. {% endfor %} +
+
+ {% endif %} + {% if results.title %}
diff --git a/apps/search/index.py b/apps/search/index.py index 484340a87..66a7b3420 100644 --- a/apps/search/index.py +++ b/apps/search/index.py @@ -832,7 +832,8 @@ class Search(SolrIndex): log.error("Cannot open snippet file for book id = %d [rev=%d], %s" % (book_id, revision, e)) return [] finally: - snippets.close() + if snippets: + snippets.close() # remove verse end markers.. snips = map(lambda s: s and s.replace("/\n", "\n"), snips) @@ -867,6 +868,8 @@ class Search(SolrIndex): res = self.apply_filters(query, filters).execute() tags = [] + pd_tags = [] + for doc in res: is_pdcounter = doc.get('is_pdcounter', False) category = doc.get('tag_category') @@ -879,16 +882,18 @@ class Search(SolrIndex): tag.category = 'pd_book' # make it look more lik a tag. else: print "Warning. cannot get pdcounter tag_id=%d from db; cat=%s" % (int(doc.get('tag_id')), category) + pd_tags.append(tag) else: tag = catalogue.models.Tag.objects.get(id=doc.get("tag_id")) - # don't add the pdcounter tag if same tag already exists - - tags.append(tag) + tags.append(tag) except catalogue.models.Tag.DoesNotExist: pass except PDCounterAuthor.DoesNotExist: pass except PDCounterBook.DoesNotExist: pass + tags_slugs = set(map(lambda t: t.slug, tags)) + tags = tags + filter(lambda t: not t.slug in tags_slugs, pd_tags) + log.debug('search_tags: %s' % tags) return tags diff --git a/apps/search/views.py b/apps/search/views.py index 36dd52cd2..2109a7398 100644 --- a/apps/search/views.py +++ b/apps/search/views.py @@ -124,15 +124,17 @@ def main(request): tags = split_tags(tags) author_results = search.search_phrase(query, 'authors', book=True) + translator_results = search.search_phrase(query, 'translators', book=True) + title_results = search.search_phrase(query, 'title', book=True) # Boost main author/title results with mixed search, and save some of its results for end of list. # boost author, title results - author_title_mixed = search.search_some(query, ['authors', 'title', 'tags'], query_terms=theme_terms) + author_title_mixed = search.search_some(query, ['authors', 'translators', 'title', 'tags'], query_terms=theme_terms) author_title_rest = [] for b in author_title_mixed: - also_in_mixed = filter(lambda ba: ba.book_id == b.book_id, author_results + title_results) + also_in_mixed = filter(lambda ba: ba.book_id == b.book_id, author_results + translator_results + title_results) for b2 in also_in_mixed: b2.boost *= 1.1 if also_in_mixed is []: @@ -155,15 +157,17 @@ def main(request): return True return False return f - f = already_found(author_results + title_results + text_phrase) + f = already_found(author_results + translator_results + title_results + text_phrase) everywhere = filter(lambda x: not f(x), everywhere) author_results = SearchResult.aggregate(author_results) + translator_results = SearchResult.aggregate(translator_results) title_results = SearchResult.aggregate(title_results) everywhere = SearchResult.aggregate(everywhere, author_title_rest) for field, res in [('authors', author_results), + ('translators', translator_results), ('title', title_results), ('text', text_phrase), ('text', everywhere)]: @@ -180,11 +184,12 @@ def main(request): return False author_results = filter(ensure_exists, author_results) + translator_results = filter(ensure_exists, translator_results) title_results = filter(ensure_exists, title_results) text_phrase = filter(ensure_exists, text_phrase) everywhere = filter(ensure_exists, everywhere) - results = author_results + title_results + text_phrase + everywhere + results = author_results + translator_results + title_results + text_phrase + everywhere # ensure books do exists & sort them results.sort(reverse=True) @@ -209,6 +214,7 @@ def main(request): {'tags': tags, 'prefix': query, 'results': {'author': author_results, + 'translator': translator_results, 'title': title_results, 'content': text_phrase, 'other': everywhere}, -- 2.20.1 From 1bae026e15a391213f57020fa0aab71840b052ff Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Fri, 2 Nov 2012 14:08:54 +0100 Subject: [PATCH 02/16] Off by one error --- apps/search/custom.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/search/custom.py b/apps/search/custom.py index e6f559b62..924a10ec6 100644 --- a/apps/search/custom.py +++ b/apps/search/custom.py @@ -147,7 +147,7 @@ class CustomSolrInterface(sunburnt.SolrInterface): break start -= 1 - while end < totlen: + while end < totlen - 1: if is_boundary(text[end + 1]): break end += 1 -- 2.20.1 From 4291cfb8aed27b119552f6334e0e5ee38ebd1ceb Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Fri, 2 Nov 2012 14:16:15 +0100 Subject: [PATCH 03/16] Don't close empty object --- apps/search/index.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/search/index.py b/apps/search/index.py index 66a7b3420..f09a42e53 100644 --- a/apps/search/index.py +++ b/apps/search/index.py @@ -93,7 +93,8 @@ class Snippets(object): def close(self): """Close snippet file""" - self.file.close() + if self.file: + self.file.close() def remove(self): self.revision = None -- 2.20.1 From c2dba41b331a28fb7de510ca0e79d00e95bec99b Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Fri, 2 Nov 2012 14:22:01 +0100 Subject: [PATCH 04/16] error message must accept None, so %d->%s --- apps/search/index.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/apps/search/index.py b/apps/search/index.py index f09a42e53..822429e75 100644 --- a/apps/search/index.py +++ b/apps/search/index.py @@ -830,11 +830,10 @@ class Search(SolrIndex): idx += 1 except IOError, e: - log.error("Cannot open snippet file for book id = %d [rev=%d], %s" % (book_id, revision, e)) + log.error("Cannot open snippet file for book id = %d [rev=%s], %s" % (book_id, revision, e)) return [] finally: - if snippets: - snippets.close() + snippets.close() # remove verse end markers.. snips = map(lambda s: s and s.replace("/\n", "\n"), snips) -- 2.20.1 From d2536ed5c7d858a7af888569c740d44644b3a9cb Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Fri, 2 Nov 2012 14:26:10 +0100 Subject: [PATCH 05/16] Make title results first --- .../catalogue/search_multiple_hits.html | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/apps/catalogue/templates/catalogue/search_multiple_hits.html b/apps/catalogue/templates/catalogue/search_multiple_hits.html index 37243023d..696271fee 100644 --- a/apps/catalogue/templates/catalogue/search_multiple_hits.html +++ b/apps/catalogue/templates/catalogue/search_multiple_hits.html @@ -46,45 +46,43 @@ {% endif %}
- - - {% if results.author %} + {% if results.title %}
-

{% trans "Results by authors" %}

+

{% trans "Results by title" %}

    - {% for author in results.author %}
  1. {% book_short author.book %}
  2. {% endfor %} + {% for result in results.title %}
  3. + {% book_short result.book %} +
  4. {% endfor %}
{% endif %} - - {% if results.translator %} + + {% if results.author %}
-

{% trans "Results by translators" %}

+

{% trans "Results by authors" %}

    - {% for translator in results.translator %}
  1. {% book_short translator.book %}
  2. {% endfor %} + {% for author in results.author %}
  3. {% book_short author.book %}
  4. {% endfor %}
{% endif %} - {% if results.title %} + {% if results.translator %}
-

{% trans "Results by title" %}

+

{% trans "Results by translators" %}

    - {% for result in results.title %}
  1. - {% book_short result.book %} -
  2. {% endfor %} + {% for translator in results.translator %}
  3. {% book_short translator.book %}
  4. {% endfor %}
{% endif %} -- 2.20.1 From ac21bdd330d4f33ec70509695f55bf65d8af0427 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Thu, 8 Nov 2012 15:50:40 +0100 Subject: [PATCH 06/16] add cover thumb to api, fix duplicate audiobooks in api --- apps/api/handlers.py | 12 +++++++++--- requirements.txt | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/apps/api/handlers.py b/apps/api/handlers.py index 437b3be4c..e04710f32 100644 --- a/apps/api/handlers.py +++ b/apps/api/handlers.py @@ -12,6 +12,7 @@ from django.core.cache import get_cache from django.core.urlresolvers import reverse from piston.handler import AnonymousBaseHandler, BaseHandler from piston.utils import rc +from sorl.thumbnail import default from api.helpers import timestamp from api.models import Deleted @@ -134,6 +135,11 @@ class BookDetails(object): def cover(cls, book): return MEDIA_BASE + book.cover.url if book.cover else '' + @classmethod + def cover_thumb(cls, book): + return MEDIA_BASE + default.backend.get_thumbnail( + book.cover, "139x193").url + class BookDetailHandler(BaseHandler, BookDetails): @@ -143,7 +149,7 @@ class BookDetailHandler(BaseHandler, BookDetails): """ allowed_methods = ['GET'] fields = ['title', 'parent', 'children'] + Book.formats + [ - 'media', 'url', 'cover'] + [ + 'media', 'url', 'cover', 'cover_thumb'] + [ category_plural[c] for c in book_tag_categories] @piwik_track @@ -192,9 +198,9 @@ class AnonymousBooksHandler(AnonymousBaseHandler, BookDetails): if top_level: books = books.filter(parent=None) if audiobooks: - books = books.filter(media__type='mp3') + books = books.filter(media__type='mp3').distinct() if daisy: - books = books.filter(media__type='daisy') + books = books.filter(media__type='daisy').distinct() if books.exists(): return books diff --git a/requirements.txt b/requirements.txt index c7e33c2f2..036031e93 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,7 +6,7 @@ South>=0.7 # migrations for django django-pipeline>=1.2 django-pagination>=1.0 django-maintenancemode>=0.10 -django-piston<=0.2.3 +django-piston==0.2.2 #django-jsonfield -e git+git://github.com/bradjasper/django-jsonfield.git@2f427368ad70bf8d9a0580df58ec0eb0654d62ae#egg=django-jsonfield django-picklefield -- 2.20.1 From 0ba524a1ec102359f38df2dcb2e0e4e522f5c67b Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Thu, 8 Nov 2012 16:23:00 +0100 Subject: [PATCH 07/16] missing l10n --- .../catalogue/locale/pl/LC_MESSAGES/django.mo | Bin 2848 -> 2908 bytes .../catalogue/locale/pl/LC_MESSAGES/django.po | 63 ++++++++++-------- 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/apps/catalogue/locale/pl/LC_MESSAGES/django.mo b/apps/catalogue/locale/pl/LC_MESSAGES/django.mo index dfd8de096dec2e19441a9b7e5d4e070018624985..ed68b42f9b69069a9f697ffc879976bb9a5b7369 100644 GIT binary patch delta 1207 zcmYk*J7`l;9LMpKCNU<_KGK@lTJ2R^8{0;6t5vb!AQA_qpimION7M|3q{SvhtYEZ* zR1l;ME_M;jBIsgp@iml+4uVh+MAV@!1q&kTQc(Q<(ldC-|9(!+J@I!z?ZB+j!s62BR!FQdWQ2A$31HZBD zpHa^*gxG%#{EY^!@Heu{<`3!}@NrRsdejP{sDACJ0eVmqc2P%o(6*;g&mBSKJ7({n zKu)Tfs~1C>h02D~MQ<#)m73o1SZT@|D|S-T3+56k`aCxhT1lMHnd-CMK_rP?M1oMM zA+}d*D;JHkiDbj=N`nuiKq;O9O$H k@PAE}d|;xc@#Jtin;9R<3=cVlR}*8o^!f41&tSsy4Y9P z+p&OJ=(Rd<$+o{mEx2s`Y};3Gl5~AT-P9%A66IEBA}y6Y)b#)QSGG~nm#G8oCG?S$h&*wS@QDM2N|?yjYHL3_^md}nwsoK~ zks\n" "Language-Team: LANGUAGE \n" "Language: \n" @@ -73,7 +73,7 @@ msgstr "Duży" msgid "Queue is full. Please try again later." msgstr "" -#: views.py:500 +#: views.py:525 #, python-format msgid "" "An error occurred: %(exception)s\n" @@ -84,20 +84,20 @@ msgstr "" "\n" "%(tb)s" -#: views.py:501 +#: views.py:526 msgid "Book imported successfully" msgstr "Książka zaimportowana" -#: views.py:503 +#: views.py:528 #, python-format msgid "Error importing file: %r" msgstr "Błąd podczas importowania pliku: %r" -#: views.py:535 +#: views.py:560 msgid "Download custom PDF" msgstr "Stwórz własny PDF" -#: views.py:536 +#: views.py:561 #: templates/catalogue/book_short.html:92 #: templates/catalogue/book_text.html:28 #: templates/catalogue/book_wide.html:63 @@ -127,10 +127,10 @@ msgid "language code" msgstr "Kod języka" #: models/book.py:35 -#: models/book.py:140 +#: models/book.py:145 #: models/collection.py:13 #: models/tag.py:34 -#: models/tag.py:76 +#: models/tag.py:83 msgid "description" msgstr "opis" @@ -164,17 +164,17 @@ msgstr "książka" msgid "books" msgstr "książki" -#: models/book.py:238 +#: models/book.py:243 #, python-format msgid "Book \"%s\" does not exist." msgstr "Utwór \"%s\" nie istnieje." -#: models/book.py:252 +#: models/book.py:257 #, python-format msgid "Book %s already exists" msgstr "Książka %s już istnieje" -#: models/book.py:585 +#: models/book.py:589 #: models/bookmedia.py:22 #, python-format msgid "%s file" @@ -331,7 +331,7 @@ msgstr "" msgid "Table of Content" msgstr "" -#: templates/catalogue/book_list.html:48 +#: templates/catalogue/book_list.html:30 msgid "↑ top ↑" msgstr "" @@ -415,7 +415,7 @@ msgid "Table of contents" msgstr "" #: templates/catalogue/book_text.html:24 -#: templates/catalogue/menu.html:27 +#: templatetags/catalogue_tags.py:412 #, fuzzy msgid "Themes" msgstr "motyw" @@ -497,32 +497,32 @@ msgid "Download the catalogue in PDF format." msgstr "" #: templates/catalogue/catalogue.html:19 -#: templates/catalogue/menu.html:7 #: templates/catalogue/search_multiple_hits.html:17 #: templates/catalogue/tagged_object_list.html:26 +#: templatetags/catalogue_tags.py:408 #, fuzzy msgid "Authors" msgstr "autor" #: templates/catalogue/catalogue.html:22 -#: templates/catalogue/menu.html:17 #: templates/catalogue/search_multiple_hits.html:25 #: templates/catalogue/tagged_object_list.html:34 +#: templatetags/catalogue_tags.py:410 msgid "Kinds" msgstr "" #: templates/catalogue/catalogue.html:25 -#: templates/catalogue/menu.html:12 #: templates/catalogue/search_multiple_hits.html:33 #: templates/catalogue/tagged_object_list.html:42 +#: templatetags/catalogue_tags.py:409 #, fuzzy msgid "Genres" msgstr "gatunek" #: templates/catalogue/catalogue.html:28 -#: templates/catalogue/menu.html:22 #: templates/catalogue/search_multiple_hits.html:41 #: templates/catalogue/tagged_object_list.html:50 +#: templatetags/catalogue_tags.py:411 #, fuzzy msgid "Epochs" msgstr "epoka" @@ -580,17 +580,21 @@ msgstr "fragment" msgid "See full category" msgstr "kategoria" -#: templates/catalogue/menu.html:32 +#: templates/catalogue/menu.html:9 +msgid "Please wait…" +msgstr "" + +#: templates/catalogue/menu.html:16 #, fuzzy msgid "All books" msgstr "książki" -#: templates/catalogue/menu.html:36 +#: templates/catalogue/menu.html:20 #, fuzzy msgid "Audiobooks" msgstr "książki" -#: templates/catalogue/menu.html:40 +#: templates/catalogue/menu.html:24 #, fuzzy msgid "DAISY" msgstr "Plik DAISY" @@ -683,19 +687,23 @@ msgstr "" msgid "Did you mean" msgstr "" -#: templates/catalogue/search_multiple_hits.html:54 -msgid "Results by authors" +#: templates/catalogue/search_multiple_hits.html:52 +msgid "Results by title" msgstr "" #: templates/catalogue/search_multiple_hits.html:67 -msgid "Results by title" +msgid "Results by authors" msgstr "" -#: templates/catalogue/search_multiple_hits.html:82 +#: templates/catalogue/search_multiple_hits.html:80 +msgid "Results by translators" +msgstr "Znalezieni tłumacze" + +#: templates/catalogue/search_multiple_hits.html:93 msgid "Results in text" msgstr "" -#: templates/catalogue/search_multiple_hits.html:99 +#: templates/catalogue/search_multiple_hits.html:110 msgid "Other results" msgstr "" @@ -826,9 +834,6 @@ msgstr "" #~ msgid "goes to public domain" #~ msgstr "trafia do domeny publicznej" -#~ msgid "translator" -#~ msgstr "tłumacz" - #~ msgid "year of translator's death" #~ msgstr "rok śmierci tłumacza" -- 2.20.1 From 06aa9a0cfb91249b55aafe26967730c3ea29ad96 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Mon, 12 Nov 2012 16:52:57 +0100 Subject: [PATCH 08/16] Add ebooks listing to api --- apps/api/handlers.py | 4 ++++ apps/api/urls.py | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/apps/api/handlers.py b/apps/api/handlers.py index e04710f32..be5993cd9 100644 --- a/apps/api/handlers.py +++ b/apps/api/handlers.py @@ -230,6 +230,10 @@ class BooksHandler(BookDetailHandler): return rc.NOT_FOUND +class EBooksHandler(AnonymousBooksHandler): + fields = ('author', 'href', 'title', 'cover') + tuple(Book.ebook_formats) + + # add categorized tags fields for Book def _tags_getter(category): @classmethod diff --git a/apps/api/urls.py b/apps/api/urls.py index e24c3c523..8a1451909 100644 --- a/apps/api/urls.py +++ b/apps/api/urls.py @@ -15,6 +15,7 @@ tag_changes_resource = Resource(handler=handlers.TagChangesHandler) changes_resource = Resource(handler=handlers.ChangesHandler) book_list_resource = CsrfExemptResource(handler=handlers.BooksHandler, authentication=auth) +ebook_list_resource = Resource(handler=handlers.EBooksHandler) #book_list_resource = Resource(handler=handlers.BooksHandler) book_resource = Resource(handler=handlers.BookDetailHandler) @@ -57,8 +58,12 @@ urlpatterns = patterns( # books by tags url(r'^(?P(?:(?:[a-z0-9-]+/){2}){0,6})books/$', book_list_resource, name='api_book_list'), + url(r'^(?P(?:(?:[a-z0-9-]+/){2}){0,6})ebooks/$', + ebook_list_resource, name='api_ebook_list'), url(r'^(?P(?:(?:[a-z0-9-]+/){2}){0,6})parent_books/$', book_list_resource, {"top_level": True}, name='api_parent_book_list'), + url(r'^(?P(?:(?:[a-z0-9-]+/){2}){0,6})parent_ebooks/$', + ebook_list_resource, {"top_level": True}, name='api_parent_ebook_list'), url(r'^(?P(?:(?:[a-z0-9-]+/){2}){0,6})audiobooks/$', book_list_resource, {"audiobooks": True}, name='api_audiobook_list'), url(r'^(?P(?:(?:[a-z0-9-]+/){2}){0,6})daisy/$', -- 2.20.1 From 5345c6e3640cc5f356b55348a5834e3a1987532d Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Tue, 13 Nov 2012 15:06:49 +0100 Subject: [PATCH 09/16] Test fix --- apps/api/handlers.py | 2 +- apps/catalogue/tests/tags.py | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/apps/api/handlers.py b/apps/api/handlers.py index be5993cd9..dbe905b00 100644 --- a/apps/api/handlers.py +++ b/apps/api/handlers.py @@ -138,7 +138,7 @@ class BookDetails(object): @classmethod def cover_thumb(cls, book): return MEDIA_BASE + default.backend.get_thumbnail( - book.cover, "139x193").url + book.cover, "139x193").url if book.cover else '' diff --git a/apps/catalogue/tests/tags.py b/apps/catalogue/tests/tags.py index 3eab3da4d..2608eb632 100644 --- a/apps/catalogue/tests/tags.py +++ b/apps/catalogue/tests/tags.py @@ -277,12 +277,11 @@ class BookTagsTests(WLTestCase): self.assertEqual([(tag.name, tag.count) for tag in related_themes], [('ChildTheme', 1), ('ParentTheme', 1), ('Theme', 2)]) - def test_main_page_tags(self): + def test_catalogue_tags(self): """ test main page tags and counts """ - from catalogue.templatetags.catalogue_tags import catalogue_menu - menu = catalogue_menu() - self.assertEqual([(tag.name, tag.book_count) for tag in menu['author']], + context = self.client.get('/katalog/').context + self.assertEqual([(tag.name, tag.book_count) for tag in context['categories']['author']], [('Jim Lazy', 1), ('Common Man', 1)]) - self.assertEqual([(tag.name, tag.book_count) for tag in menu['theme']], + self.assertEqual([(tag.name, tag.book_count) for tag in context['categories']['theme']], [('ChildTheme', 1), ('ParentTheme', 1), ('Theme', 2)]) -- 2.20.1 From b34b62e9545e4c8a887c4ea54203082fb6ecec42 Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Wed, 21 Nov 2012 11:03:17 +0100 Subject: [PATCH 10/16] Filter some search characters which make Solr too unhappy. --- apps/search/views.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/apps/search/views.py b/apps/search/views.py index 2109a7398..9a0b469a1 100644 --- a/apps/search/views.py +++ b/apps/search/views.py @@ -3,7 +3,6 @@ from django.conf import settings from django.shortcuts import render_to_response, get_object_or_404 from django.template import RequestContext -from django.contrib.auth.decorators import login_required from django.views.decorators import cache from django.http import HttpResponse, HttpResponseRedirect, Http404, HttpResponsePermanentRedirect from django.utils.translation import ugettext as _ @@ -13,9 +12,7 @@ from catalogue.models import Book, Tag, Fragment from pdcounter.models import Author as PDCounterAuthor, BookStub as PDCounterBook from catalogue.views import JSONResponse from search import Search, SearchResult -from lucene import StringReader from suggest.forms import PublishingSuggestForm -from time import sleep import re #import enchant import json @@ -28,6 +25,13 @@ def match_word_re(word): return "[[:<:]]%s[[:>:]]" % word +query_syntax_chars = re.compile(r"[\\/*:(){}]") + + +def remove_query_syntax_chars(query, replace=' '): + return query_syntax_chars.sub(' ', query) + + def did_you_mean(query, tokens): return query # change = {} @@ -59,6 +63,8 @@ def hint(request): if len(prefix) < 2: return JSONResponse([]) + prefix = remove_query_syntax_chars(prefix) + search = Search() # tagi beda ograniczac tutaj # ale tagi moga byc na ksiazce i na fragmentach @@ -114,6 +120,9 @@ def main(request): return render_to_response('catalogue/search_too_short.html', {'prefix': query}, context_instance=RequestContext(request)) + + query = remove_query_syntax_chars(query) + search = Search() theme_terms = search.index.analyze(text=query, field="themes_pl") \ @@ -191,7 +200,8 @@ def main(request): results = author_results + translator_results + title_results + text_phrase + everywhere # ensure books do exists & sort them - results.sort(reverse=True) + for res in (author_results, translator_results, title_results, text_phrase, everywhere): + res.sort(reverse=True) # We don't want to redirect to book text, but rather display result page even with one result. # if len(results) == 1: -- 2.20.1 From e88395c433fa6004bee50c144b058d0108a61c68 Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Wed, 28 Nov 2012 16:57:53 +0100 Subject: [PATCH 11/16] remove jvm leftovers, gaa! --- apps/catalogue/models/listeners.py | 1 - apps/pdcounter/models.py | 1 - apps/search/__init__.py | 2 -- wolnelektury/settings/custom.py | 3 --- 4 files changed, 7 deletions(-) diff --git a/apps/catalogue/models/listeners.py b/apps/catalogue/models/listeners.py index 93ad2d788..41c974ade 100644 --- a/apps/catalogue/models/listeners.py +++ b/apps/catalogue/models/listeners.py @@ -61,7 +61,6 @@ if not settings.NO_SEARCH_INDEX: def _remove_book_from_index_handler(sender, instance, **kwargs): """ remove the book from search index, when it is deleted.""" import search - search.JVM.attachCurrentThread() idx = search.Index() idx.open(timeout=10000) # 10 seconds timeout. try: diff --git a/apps/pdcounter/models.py b/apps/pdcounter/models.py index 35cbe2999..50eb43e1f 100644 --- a/apps/pdcounter/models.py +++ b/apps/pdcounter/models.py @@ -92,7 +92,6 @@ if not settings.NO_SEARCH_INDEX: def update_index(sender, instance, **kwargs): import search print "update pd index %s [update %s]" % (instance, 'created' in kwargs) - search.JVM.attachCurrentThread() idx = search.Index() idx.open() try: diff --git a/apps/search/__init__.py b/apps/search/__init__.py index 279d281e3..8081416c6 100644 --- a/apps/search/__init__.py +++ b/apps/search/__init__.py @@ -1,4 +1,2 @@ -#import lucene -#from index import Index, Search, ReusableIndex, SearchResult, JVM, IndexChecker, IndexStore from index import Index, Search, SearchResult diff --git a/wolnelektury/settings/custom.py b/wolnelektury/settings/custom.py index 446c730ee..a0bab7a64 100644 --- a/wolnelektury/settings/custom.py +++ b/wolnelektury/settings/custom.py @@ -16,6 +16,3 @@ CATALOGUE_CUSTOMPDF_RATE_LIMIT = '1/m' # set to 'new' or 'old' to skip time-consuming test # for TeX morefloats library version LIBRARIAN_PDF_MOREFLOATS = None - -# Max memory used by search -JVM_MAXHEAP = '256m' -- 2.20.1 From 8eaff819afa954d679e9cf6ac2b3ad2436acfbd3 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Wed, 12 Dec 2012 14:33:39 +0100 Subject: [PATCH 12/16] First obvious accessibility fixes. --- apps/catalogue/templates/catalogue/book_mini_box.html | 8 ++------ apps/catalogue/templatetags/catalogue_tags.py | 4 +++- apps/wolnelektury_core/templates/main_page.html | 8 ++++---- apps/wolnelektury_core/templates/superbase.html | 6 ++++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/apps/catalogue/templates/catalogue/book_mini_box.html b/apps/catalogue/templates/catalogue/book_mini_box.html index 731a8d334..9dd5cf061 100755 --- a/apps/catalogue/templates/catalogue/book_mini_box.html +++ b/apps/catalogue/templates/catalogue/book_mini_box.html @@ -8,14 +8,10 @@ {% empty %} {{ book.cover.url }} {% endthumbnail %} - " alt="Cover" class="cover" /> + " alt="{{ author_str }} – {{ book.title }}" class="cover" /> {% endif %}
- - {% for name, url in related.tags.author %} - {{ name }}{% if not forloop.last %}, {% endif %} - {% endfor %} - + {{ author_str }} {{ book.title }}
diff --git a/apps/catalogue/templatetags/catalogue_tags.py b/apps/catalogue/templatetags/catalogue_tags.py index 8cf3acf59..af9bfae74 100644 --- a/apps/catalogue/templatetags/catalogue_tags.py +++ b/apps/catalogue/templatetags/catalogue_tags.py @@ -345,9 +345,11 @@ def book_short(context, book): @register.inclusion_tag('catalogue/book_mini_box.html') def book_mini(book): + author_str = ", ".join(name + for name, url in book.related_info()['tags']['author']) return { 'book': book, - 'related': book.related_info(), + 'author_str': author_str, } diff --git a/apps/wolnelektury_core/templates/main_page.html b/apps/wolnelektury_core/templates/main_page.html index 6b7c46aac..57a442e92 100755 --- a/apps/wolnelektury_core/templates/main_page.html +++ b/apps/wolnelektury_core/templates/main_page.html @@ -60,8 +60,8 @@
  • {% trans "Publishing plan" %}
  • API
  • OAI-PMH
  • -
  • Leśmianator
  • -
  • Materiały do nauki j. polskiego
  • +
  • Leśmianator
  • +
  • Materiały do nauki j. polskiego
  • @@ -76,11 +76,11 @@ diff --git a/apps/wolnelektury_core/templates/superbase.html b/apps/wolnelektury_core/templates/superbase.html index b0067acc7..ac24de3fe 100644 --- a/apps/wolnelektury_core/templates/superbase.html +++ b/apps/wolnelektury_core/templates/superbase.html @@ -1,5 +1,5 @@ - + {% load cache compressed i18n %} {% load static from staticfiles %} {% load catalogue_tags reporting_stats sponsor_tags %} @@ -42,7 +42,8 @@
    @@ -135,6 +136,7 @@ {% csrf_token %} -- 2.20.1 From a42b731727d0c4b8e372d001c5a1be776067eae8 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Wed, 12 Dec 2012 14:35:58 +0100 Subject: [PATCH 13/16] Collections in menu --- .../catalogue/locale/pl/LC_MESSAGES/django.mo | Bin 2908 -> 2953 bytes .../catalogue/locale/pl/LC_MESSAGES/django.po | 30 +++++++++++------- apps/catalogue/models/collection.py | 4 +++ .../templates/catalogue/catalogue.html | 11 ++++--- .../templates/catalogue/collection_list.html | 5 +++ apps/catalogue/templates/catalogue/menu.html | 8 +++++ apps/catalogue/templatetags/catalogue_tags.py | 5 +++ apps/catalogue/views.py | 6 ++-- apps/wolnelektury_core/static/css/header.css | 4 +++ apps/wolnelektury_core/static/css/screen.css | 5 +++ 10 files changed, 60 insertions(+), 18 deletions(-) create mode 100755 apps/catalogue/templates/catalogue/collection_list.html diff --git a/apps/catalogue/locale/pl/LC_MESSAGES/django.mo b/apps/catalogue/locale/pl/LC_MESSAGES/django.mo index ed68b42f9b69069a9f697ffc879976bb9a5b7369..a04bce5742450db30b5a07cc39c33b3c6bf5b52d 100644 GIT binary patch delta 1272 zcmYk*J!n%=7{>9_G%-yYO>Au&zhaEm#@4hqX)Ri*OS(h_KM=&FMQVn&!6+$WQM`*0 zMF*wmAPy}kC@wffQ}K}Z{%+1a=RIHdzHhzS=6-1M z-ZGSaVgvEA&X^otsOLhN@fzdDSxn+X)T6h!7U!`Q7jPZ=ea19m0@be@o3S6);67Bp z5nN@AYo@qqpyCRu;Z2OY9gm?gDF(vOZNEl3Ji9oCes@5Rd;-!9~5=IETn7pV3NsI6Z_ z9aV(cxozBZaYLQSqPFM&hVU3_%TJ=(l~8AR4K=_F>c}2oJ3d3T|BTA>1Do(Ss(+YD zweLXfz@8xIuY@@&G~h65rV~gXa|R=L9>aJYHNai_{E_tuY5{ZBs`U-3-#gTfensW~ zjvDu8kp0(#AP21kVbs7;)Cv>GshCdWXVP4hU=X!}EUMjMRG#Cg2@j)=tZ3^?sD9^A z`7YY$WtSU{to8!+qTXzMhAE>o`=E89qDAnn$2>0G`+ zhtLAtE-tk*!3?32AT|-334My1IXh<76FSFkLPa~KvYpUsS&P|9>>!eac47;mqEA&v z>>+j%wk*w0Tc?tqo~>{8=^c$tm%Zi2Y_U+tk4}yiPn9YG--suZNu@LKbl-rpyUR&C vPVmsd)RFwzu@Ws(LnkKl1M!TLR-=FIDtG+lx`zG5LVjX&JYR_g_ImyTY8+^d delta 1216 zcmYk+Pe>GD7{~F)b+>KDQrm3RGF{89&D3_Ze7%|Lecj(`y71P=l#sQ^Um|m`@SlP&o5WmKN`e*RhK zjBj5#(2}nEg-ukVU*5ju?f*~-YgrbVLJi!2581XRD*_ zPg&B^ba1c>yHQJh2Gya6+PhIy;yb9Vx{En{jOss+%CmxL{DiuH4b^`OHS>BpDPJ3E zyf9$>^@JB_ppRX`M!bp*cpWvsxL?2LP9l@AX?NBwqwaf+TA4*u{$i)HW z_1C}~G-!r@kX5$7sCOVvr38(r8DvoXx=;i3pdL6xZQ(_4FQV?dg334S*RLTv73Jzj zjUSZ*)Jmw%DoUn-4ikFowVd0F9$HI#l+a5U5-R$H4-%Sfp3uJQ)9xb*!~oGtsKkiU zvFNZ`X-V3NE^j-5+NVxJFHR4ka;Qo)Lv4==6N}18>MU`b(C4gAwS&+qhALA5H(TFyogU!`VynDAnYxi&4#DX^@lUhlI`10D@)0Vn#xe>eC$7gbyxTR diff --git a/apps/catalogue/locale/pl/LC_MESSAGES/django.po b/apps/catalogue/locale/pl/LC_MESSAGES/django.po index 7682cd2da..46e15242b 100644 --- a/apps/catalogue/locale/pl/LC_MESSAGES/django.po +++ b/apps/catalogue/locale/pl/LC_MESSAGES/django.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2012-11-08 16:21+0100\n" -"PO-Revision-Date: 2012-11-08 16:21+0100\n" +"POT-Creation-Date: 2012-12-12 14:09+0100\n" +"PO-Revision-Date: 2012-12-12 14:09+0100\n" "Last-Translator: Radek Czajka \n" "Language-Team: LANGUAGE \n" "Language: \n" @@ -73,7 +73,7 @@ msgstr "Duży" msgid "Queue is full. Please try again later." msgstr "" -#: views.py:525 +#: views.py:528 #, python-format msgid "" "An error occurred: %(exception)s\n" @@ -84,20 +84,20 @@ msgstr "" "\n" "%(tb)s" -#: views.py:526 +#: views.py:529 msgid "Book imported successfully" msgstr "Książka zaimportowana" -#: views.py:528 +#: views.py:531 #, python-format msgid "Error importing file: %r" msgstr "Błąd podczas importowania pliku: %r" -#: views.py:560 +#: views.py:563 msgid "Download custom PDF" msgstr "Stwórz własny PDF" -#: views.py:561 +#: views.py:564 #: templates/catalogue/book_short.html:92 #: templates/catalogue/book_text.html:28 #: templates/catalogue/book_wide.html:63 @@ -415,7 +415,7 @@ msgid "Table of contents" msgstr "" #: templates/catalogue/book_text.html:24 -#: templatetags/catalogue_tags.py:412 +#: templatetags/catalogue_tags.py:416 #, fuzzy msgid "Themes" msgstr "motyw" @@ -499,7 +499,7 @@ msgstr "" #: templates/catalogue/catalogue.html:19 #: templates/catalogue/search_multiple_hits.html:17 #: templates/catalogue/tagged_object_list.html:26 -#: templatetags/catalogue_tags.py:408 +#: templatetags/catalogue_tags.py:412 #, fuzzy msgid "Authors" msgstr "autor" @@ -507,14 +507,14 @@ msgstr "autor" #: templates/catalogue/catalogue.html:22 #: templates/catalogue/search_multiple_hits.html:25 #: templates/catalogue/tagged_object_list.html:34 -#: templatetags/catalogue_tags.py:410 +#: templatetags/catalogue_tags.py:414 msgid "Kinds" msgstr "" #: templates/catalogue/catalogue.html:25 #: templates/catalogue/search_multiple_hits.html:33 #: templates/catalogue/tagged_object_list.html:42 -#: templatetags/catalogue_tags.py:409 +#: templatetags/catalogue_tags.py:413 #, fuzzy msgid "Genres" msgstr "gatunek" @@ -522,7 +522,7 @@ msgstr "gatunek" #: templates/catalogue/catalogue.html:28 #: templates/catalogue/search_multiple_hits.html:41 #: templates/catalogue/tagged_object_list.html:50 -#: templatetags/catalogue_tags.py:411 +#: templatetags/catalogue_tags.py:415 #, fuzzy msgid "Epochs" msgstr "epoka" @@ -531,6 +531,11 @@ msgstr "epoka" msgid "Themes and topics" msgstr "" +#: templates/catalogue/catalogue.html:34 +#: templates/catalogue/menu.html:29 +msgid "Collections" +msgstr "Kolekcje" + #: templates/catalogue/daisy_list.html:6 #: templates/catalogue/daisy_list.html:12 msgid "Listing of all DAISY files" @@ -581,6 +586,7 @@ msgid "See full category" msgstr "kategoria" #: templates/catalogue/menu.html:9 +#: templates/catalogue/menu.html.py:31 msgid "Please wait…" msgstr "" diff --git a/apps/catalogue/models/collection.py b/apps/catalogue/models/collection.py index 1c9027c31..daee48461 100644 --- a/apps/catalogue/models/collection.py +++ b/apps/catalogue/models/collection.py @@ -23,3 +23,7 @@ class Collection(models.Model): def __unicode__(self): return self.title + + @models.permalink + def get_absolute_url(self): + return ("collection", [self.slug]) diff --git a/apps/catalogue/templates/catalogue/catalogue.html b/apps/catalogue/templates/catalogue/catalogue.html index 8a558abca..31c4d5b99 100644 --- a/apps/catalogue/templates/catalogue/catalogue.html +++ b/apps/catalogue/templates/catalogue/catalogue.html @@ -20,16 +20,19 @@
    {% tag_list categories.author %}

    {% trans "Kinds" %}

    -
    {% tag_list categories.kind %}
    +
    {% tag_list categories.kind %}

    {% trans "Genres" %}

    -
    {% tag_list categories.genre %}
    +
    {% tag_list categories.genre %}

    {% trans "Epochs" %}

    -
    {% tag_list categories.epoch %}
    +
    {% tag_list categories.epoch %}

    {% trans "Themes and topics" %}

    -
    {% tag_list fragment_tags %}
    +
    {% tag_list fragment_tags %}
    + +

    {% trans "Collections" %}

    +
    {% collection_list collections %}
    {% endblock %} diff --git a/apps/catalogue/templates/catalogue/collection_list.html b/apps/catalogue/templates/catalogue/collection_list.html new file mode 100755 index 000000000..38466f157 --- /dev/null +++ b/apps/catalogue/templates/catalogue/collection_list.html @@ -0,0 +1,5 @@ + diff --git a/apps/catalogue/templates/catalogue/menu.html b/apps/catalogue/templates/catalogue/menu.html index 72bf5e6fe..c87cd3300 100644 --- a/apps/catalogue/templates/catalogue/menu.html +++ b/apps/catalogue/templates/catalogue/menu.html @@ -23,4 +23,12 @@ {% trans "DAISY" %} + + \ No newline at end of file diff --git a/apps/catalogue/templatetags/catalogue_tags.py b/apps/catalogue/templatetags/catalogue_tags.py index af9bfae74..6a30a9c26 100644 --- a/apps/catalogue/templatetags/catalogue_tags.py +++ b/apps/catalogue/templatetags/catalogue_tags.py @@ -311,6 +311,11 @@ def inline_tag_list(tags, choices=None): return tag_list(tags, choices) +@register.inclusion_tag('catalogue/collection_list.html') +def collection_list(collections): + return locals() + + @register.inclusion_tag('catalogue/book_info.html') def book_info(book): return locals() diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index 66036bf77..6dd3d7ec1 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -21,11 +21,10 @@ from django.utils.translation import ugettext as _, ugettext_lazy from django.views.decorators.cache import never_cache from ajaxable.utils import JSONResponse, AjaxableFormView - from catalogue import models from catalogue import forms from catalogue.utils import split_tags, MultiQuerySet -from catalogue.templatetags.catalogue_tags import tag_list +from catalogue.templatetags.catalogue_tags import tag_list, collection_list from pdcounter import models as pdcounter_models from pdcounter import views as pdcounter_views from suggest.forms import PublishingSuggestForm @@ -43,6 +42,7 @@ def catalogue(request): tag.count = tag.book_count categories = split_tags(tags) fragment_tags = categories.get('theme', []) + collections = models.Collection.objects.all() if request.is_ajax(): render_tag_list = lambda x: render_to_string( @@ -50,6 +50,8 @@ def catalogue(request): output = {'theme': render_tag_list(fragment_tags)} for category, tags in categories.items(): output[category] = render_tag_list(tags) + output['collections'] = render_to_string( + 'catalogue/collection_list.html', collection_list(collections)) return JSONResponse(output) else: return render_to_response('catalogue/catalogue.html', locals(), diff --git a/apps/wolnelektury_core/static/css/header.css b/apps/wolnelektury_core/static/css/header.css index fefb65ab0..3e1a4af00 100755 --- a/apps/wolnelektury_core/static/css/header.css +++ b/apps/wolnelektury_core/static/css/header.css @@ -153,6 +153,10 @@ a.menu { padding-top: 1.8em; color: #0c7076; } +#menu a.hidden-box-trigger:hover { + border-bottom: 3px solid white; + margin-bottom: -3px; +} a.menu span { font-size: 1.1em; } diff --git a/apps/wolnelektury_core/static/css/screen.css b/apps/wolnelektury_core/static/css/screen.css index 138121e0c..8522996dc 100644 --- a/apps/wolnelektury_core/static/css/screen.css +++ b/apps/wolnelektury_core/static/css/screen.css @@ -18,6 +18,11 @@ -webkit-column-width: 12em; } +#menu-collections ul { + width: 18em; +} + + #header-content, div#main-content, div#half-header-content, #footer-content { width: 97.5em; margin: auto; -- 2.20.1 From cd1d79e58ca4ea2aa8a84b66bf6f1c1bf9fa902d Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Fri, 21 Dec 2012 10:34:06 +0100 Subject: [PATCH 14/16] move collections menu --- apps/catalogue/templates/catalogue/menu.html | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/catalogue/templates/catalogue/menu.html b/apps/catalogue/templates/catalogue/menu.html index c87cd3300..ad5e386bc 100644 --- a/apps/catalogue/templates/catalogue/menu.html +++ b/apps/catalogue/templates/catalogue/menu.html @@ -11,6 +11,14 @@ {% endfor %} + + - - \ No newline at end of file -- 2.20.1 From 4616e23c1bd0474db31b4bc303aa17b61fc3cefb Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Sun, 10 Mar 2013 16:40:50 +0100 Subject: [PATCH 15/16] print cleanups --- apps/search/custom.py | 1 - apps/search/index.py | 6 +----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/apps/search/custom.py b/apps/search/custom.py index 924a10ec6..dcb55eb44 100644 --- a/apps/search/custom.py +++ b/apps/search/custom.py @@ -179,7 +179,6 @@ class CustomSolrInterface(sunburnt.SolrInterface): snip = text[start:end] matches.sort(lambda a, b: cmp(b[0], a[0])) - print matches for (s, e) in matches: off = - start diff --git a/apps/search/index.py b/apps/search/index.py index 822429e75..85bcb616d 100644 --- a/apps/search/index.py +++ b/apps/search/index.py @@ -134,7 +134,6 @@ class Index(SolrIndex): for res in ids: uids.add(res['uid']) st += rows - # print "Will delete %s" % ','.join([x for x in uids]) if uids: self.index.delete(uids) return True @@ -465,7 +464,6 @@ class Index(SolrIndex): text=u''.join(footnote), is_footnote=True) self.index.add(doc) - #print "@ footnote text: %s" % footnote footnote = [] # handle fragments and themes. @@ -498,7 +496,6 @@ class Index(SolrIndex): fragment_anchor=fid, text=fix_format(frag['text']), themes=frag['themes']) - #print '@ FRAG %s' % frag['content'] self.index.add(doc) # Collect content. @@ -511,7 +508,6 @@ class Index(SolrIndex): # in the end, add a section text. doc = add_part(snippets, header_index=position, header_type=header.tag, text=fix_format(content)) - #print '@ CONTENT: %s' % fix_format(content) self.index.add(doc) @@ -881,7 +877,7 @@ class Search(SolrIndex): tag = PDCounterBook.objects.get(id=doc.get('tag_id')) tag.category = 'pd_book' # make it look more lik a tag. else: - print "Warning. cannot get pdcounter tag_id=%d from db; cat=%s" % (int(doc.get('tag_id')), category) + print ("Warning. cannot get pdcounter tag_id=%d from db; cat=%s" % (int(doc.get('tag_id')), category)).encode('utf-8') pd_tags.append(tag) else: tag = catalogue.models.Tag.objects.get(id=doc.get("tag_id")) -- 2.20.1 From 60817334eba7db4b2b45e640fe91f8dc157efc47 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Thu, 14 Mar 2013 16:46:32 +0100 Subject: [PATCH 16/16] Old unused imports. --- apps/opds/views.py | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/opds/views.py b/apps/opds/views.py index f7658c22b..23c320e62 100644 --- a/apps/opds/views.py +++ b/apps/opds/views.py @@ -17,7 +17,6 @@ from basicauth import logged_in_or_basicauth, factory_decorator from catalogue.models import Book, Tag from search.views import Search, SearchResult -from lucene import Term, QueryWrapperFilter, TermQuery import operator import logging import re -- 2.20.1