From: Marcin Koziej Date: Wed, 28 Dec 2011 09:14:23 +0000 (+0100) Subject: merge wyszukiwania. X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/9fbf0c4158a9427442171629a564e2de7780b5b7?ds=sidebyside;hp=-c merge wyszukiwania. Merge branch 'pretty' of github.com:fnp/wolnelektury into pretty Conflicts: lib/librarian wolnelektury/templates/base.html --- 9fbf0c4158a9427442171629a564e2de7780b5b7 diff --combined apps/catalogue/models.py index a180c650c,f92ebd38b..2effb3bc7 --- a/apps/catalogue/models.py +++ b/apps/catalogue/models.py @@@ -24,15 -24,13 +24,15 @@@ from newtagging.models import TagBase, from newtagging import managers from catalogue.fields import JSONField, OverwritingFileField from catalogue.utils import create_zip, split_tags -from catalogue.tasks import touch_tag +from catalogue.tasks import touch_tag, index_book from shutil import copy from glob import glob import re from os import path +import search + TAG_CATEGORIES = ( ('author', _('author')), ('epoch', _('epoch')), @@@ -515,7 -513,7 +515,7 @@@ class Book(models.Model) for ebook_format in self.ebook_formats: if self.has_media(ebook_format): formats.append(u'%s' % ( - "", #self.get_media(ebook_format).url, + self.get_media(ebook_format).url, ebook_format.upper() )) @@@ -731,19 -729,6 +731,19 @@@ result = create_zip.delay(paths, self.fileid()) return result.wait() + def search_index(self, book_info=None): + if settings.CELERY_ALWAYS_EAGER: + idx = search.ReusableIndex() + else: + idx = search.Index() + + idx.open() + try: + idx.index_book(self, book_info) + idx.index_tags() + finally: + idx.close() + @classmethod def from_xml_file(cls, xml_file, **kwargs): from django.core.files import File @@@ -762,8 -747,7 +762,8 @@@ @classmethod def from_text_and_meta(cls, raw_file, book_info, overwrite=False, - build_epub=True, build_txt=True, build_pdf=True, build_mobi=True): + build_epub=True, build_txt=True, build_pdf=True, build_mobi=True, + search_index=True): import re from sortify import sortify @@@ -831,9 -815,6 +831,9 @@@ if not settings.NO_BUILD_MOBI and build_mobi: book.build_mobi() + if not settings.NO_SEARCH_INDEX and search_index: + index_book.delay(book.id, book_info) + book_descendants = list(book.children.all()) descendants_tags = set() # add l-tag to descendants and their fragments @@@ -1035,7 -1016,7 +1035,7 @@@ class Fragment(models.Model) verbose_name_plural = _('fragments') def get_absolute_url(self): - return '%s#m%s' % (self.book.get_html_url(), self.anchor) + return '%s#m%s' % (reverse('book_text', args=[self.book.slug]), self.anchor) def reset_short_html(self): if self.id is None: diff --combined apps/catalogue/urls.py index e128c60b1,0b2a1bb41..fa472c970 --- a/apps/catalogue/urls.py +++ b/apps/catalogue/urls.py @@@ -7,7 -7,12 +7,12 @@@ from catalogue.feeds import AudiobookFe from catalogue.models import Book from picture.models import Picture - urlpatterns = patterns('catalogue.views', + urlpatterns = patterns('picture.views', + # pictures - currently pictures are coupled with catalogue, hence the url is here + url(r'^obraz/?$', 'picture_list'), + url(r'^obraz/(?P%s)/?$' % Picture.URLID_RE, 'picture_detail') + ) + \ + patterns('catalogue.views', url(r'^$', 'catalogue', name='catalogue'), url(r'^polki/(?P[a-zA-Z0-9-]+)/formaty/$', 'shelf_book_formats', name='shelf_book_formats'), url(r'^polki/(?P[a-zA-Z0-9-]+)/(?P%s)/usun$' % Book.URLID_RE, 'remove_from_shelf', name='remove_from_shelf'), @@@ -21,7 -26,7 +26,7 @@@ url(r'^polki/nowa/$', 'new_set', name='new_set'), url(r'^tags/$', 'tags_starting_with', name='hint'), url(r'^jtags/$', 'json_tags_starting_with', name='jhint'), - url(r'^szukaj/$', 'search', name='search'), + url(r'^szukaj/$', 'search', name='old_search'), # zip #url(r'^zip/pdf\.zip$', 'download_zip', {'format': 'pdf', 'slug': None}, 'download_zip_pdf'), @@@ -41,9 -46,4 +46,4 @@@ url(r'^custompdf/(?P%s).pdf' % Book.FILEID_RE, 'download_custom_pdf'), - ) + patterns('picture.views', - # pictures - currently pictures are coupled with catalogue, hence the url is here - url(r'^obraz/?$', 'picture_list'), - url(r'^obraz/(?P%s)/?$' % Picture.URLID_RE, 'picture_detail') - ) - + ) diff --combined wolnelektury/settings.py index fe2572904,18e8d7573..f01ab182f --- a/wolnelektury/settings.py +++ b/wolnelektury/settings.py @@@ -60,7 -60,6 +60,7 @@@ USE_I18N = Tru # Example: "/home/media/media.lawrence.com/" MEDIA_ROOT = path.join(PROJECT_DIR, '../media') STATIC_ROOT = path.join(PROJECT_DIR, 'static') +SEARCH_INDEX = path.join(MEDIA_ROOT, 'search') # URL that handles the media served from MEDIA_ROOT. Make sure to use a # trailing slash if there is a path component (optional in other cases). @@@ -154,7 -153,6 +154,7 @@@ INSTALLED_APPS = 'stats', 'suggest', 'picture', + 'search', ] #CACHE_BACKEND = 'locmem:///?max_entries=3000' @@@ -172,11 -170,10 +172,12 @@@ COMPRESS_CSS = 'css/header.css', 'css/main_page.css', 'css/dialogs.css', + 'css/picture_box.css', 'css/book_box.css', 'css/catalogue.css', 'css/sponsors.css', + + 'css/ui-lightness/jquery-ui-1.8.16.custom.css', ], 'output_filename': 'css/all.min?.css', }, @@@ -201,15 -198,12 +202,16 @@@ COMPRESS_JS = 'js/jquery.countdown-es.js', 'js/jquery.countdown-lt.js', 'js/jquery.countdown-ru.js', 'js/jquery.countdown-fr.js', + 'js/jquery-ui-1.8.16.custom.min.js', + 'js/locale.js', 'js/dialogs.js', 'js/sponsors.js', + 'js/base.js', 'js/pdcounter.js', + 'js/search.js', + #~ 'js/jquery.autocomplete.js', #~ 'js/jquery.labelify.js', 'js/catalogue.js', ), @@@ -256,9 -250,7 +258,9 @@@ MAX_TAG_LIST = NO_BUILD_EPUB = False NO_BUILD_TXT = False NO_BUILD_PDF = False -NO_BUILD_MOBI = False +NO_BUILD_MOBI = True +NO_SEARCH_INDEX = False +SEARCH_INDEX_PARALLEL = False ALL_EPUB_ZIP = 'wolnelektury_pl_epub' ALL_PDF_ZIP = 'wolnelektury_pl_pdf' @@@ -279,7 -271,6 +281,7 @@@ BROKER_PASSWORD = "guest BROKER_VHOST = "/" + # Load localsettings, if they exist try: from localsettings import * diff --combined wolnelektury/static/js/search.js index e58d37256,000000000..c41a672d0 mode 100644,000000..100644 --- a/wolnelektury/static/js/search.js +++ b/wolnelektury/static/js/search.js @@@ -1,49 -1,0 +1,49 @@@ + +var __bind = function (self, fn) { + return function() { fn.apply(self, arguments); }; +}; + +(function($){ + $.widget("wl.search", { + options: { + minLength: 0, + }, + + _create: function() { + var opts = { + minLength: this.options.minLength, + select: __bind(this, this.enter), + focus: function() { return false; }, + source: this.element.data('source'), + }; + this.element.autocomplete(opts).data("autocomplete")._renderItem = __bind(this, this.render_item); + }, + + enter: function(event, ui) { + if (ui.item.url != undefined) { + location.href = ui.item.url; + } else { + this.element.closest('form').submit(); + } + }, + + render_item: function (ul, item) { + return $("
  • ").data('item.autocomplete', item) + .append(''+item.label+ ' ('+item.category+')') + .appendTo(ul); + }, + + destroy: function() { + + }, + + + + }); + + $(function() { - $("#search input[name=q]").search(); ++ $("#search-area input[name=q]").search(); + + }); + +})(jQuery); diff --combined wolnelektury/templates/base.html index d1bf19e8a,4409486ed..48f13adb2 --- a/wolnelektury/templates/base.html +++ b/wolnelektury/templates/base.html @@@ -2,6 -2,7 +2,7 @@@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> {% load i18n compressed catalogue_tags sponsor_tags %} + {% load reporting_stats %} @@@ -20,7 -21,7 +21,7 @@@ {% block bodycontent %} -