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')),
for ebook_format in self.ebook_formats:
if self.has_media(ebook_format):
formats.append(u'<a href="%s">%s</a>' % (
- "", #self.get_media(ebook_format).url,
+ self.get_media(ebook_format).url,
ebook_format.upper()
))
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
@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
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
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:
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<picture>%s)/?$' % Picture.URLID_RE, 'picture_detail')
+ ) + \
+ patterns('catalogue.views',
url(r'^$', 'catalogue', name='catalogue'),
url(r'^polki/(?P<shelf>[a-zA-Z0-9-]+)/formaty/$', 'shelf_book_formats', name='shelf_book_formats'),
url(r'^polki/(?P<shelf>[a-zA-Z0-9-]+)/(?P<book>%s)/usun$' % Book.URLID_RE, 'remove_from_shelf', name='remove_from_shelf'),
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'),
url(r'^custompdf/(?P<book_fileid>%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<picture>%s)/?$' % Picture.URLID_RE, 'picture_detail')
- )
-
+ )
# 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).
'stats',
'suggest',
'picture',
+ 'search',
]
#CACHE_BACKEND = 'locmem:///?max_entries=3000'
'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',
},
'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',
),
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'
BROKER_VHOST = "/"
+
# Load localsettings, if they exist
try:
from localsettings import *
--- /dev/null
- $("#search input[name=q]").search();
+
+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 $("<li></li>").data('item.autocomplete', item)
+ .append('<a href="'+item.url+'">'+item.label+ ' ('+item.category+')</a>')
+ .appendTo(ul);
+ },
+
+ destroy: function() {
+
+ },
+
+
+
+ });
+
+ $(function() {
++ $("#search-area input[name=q]").search();
+
+ });
+
+})(jQuery);
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
{% load i18n compressed catalogue_tags sponsor_tags %}
+ {% load reporting_stats %}
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
{% block bodycontent %}
- <div id="header" class="grid-line">
+ <div id="header">
<div id="header-content">
<div id="logo">
</div>
<div id="tagline">
- <a href=''>1666</a> darmowych lektur do których masz <a href=''>prawo</a>
+ <span>
+ {% count_books book_count %}
+ {% url book_list as b %}
+ {% url book_list as r %}
+ {% blocktrans count book_count as c %}
+ <a href='{{b}}'>{{c}}</a> free reading you have <a href='{{r}}'>right to</a>
+ {% plural %}
+ <a href='{{b}}'>{{c}}</a> free readings you have <a href='{{r}}'>right to</a>
+ {% endblocktrans %}
+ </span>
</div>
<p id="user-info" class="mono">
- <form id="search" action="/fullsearch/">
- <form id="search-area">
++ <form id="search-area" action="/fullsearch/">
- <span id="search-field">
- <input title="np. Leśmian" name="q" autocomplete="off">
+ <span id="search-field" class="grid-line">
+ <input title="np. Leśmian" name="q" autocomplete="off" data-source="/fullsearch/hint/">
</span><span id="search-button">
<button type='submit'><span class="mono">{% trans "Search" %}</span></button>
</span>
<div id="nav-line">
<ul id="catalogue">
- <li><a href="{% url book_list %}"><span class='mono'>{% trans "All books" %}</span></a></li>
- <li><a href="{% url audiobook_list %}"><span class='mono'>{% trans "Audiobooks" %}</span></a></li>
- <li><a href="{% url daisy_list %}"><span class='mono'>{% trans "DAISY" %}</span></a></li>
<li><a href="{% url catalogue %}#autorzy"><span class='mono'>{% trans "Authors" %}</span></a></li>
- <li><a href="{% url catalogue %}#epoki"><span class='mono'>{% trans "Epochs" %}</span></a></li>
- <li><a href="{% url catalogue %}#rodzaje"><span class='mono'>{% trans "Kinds" %}</span></a></li>
<li><a href="{% url catalogue %}#gatunki"><span class='mono'>{% trans "Genres" %}</span></a></li>
+ <li><a href="{% url catalogue %}#rodzaje"><span class='mono'>{% trans "Kinds" %}</span></a></li>
+ <li><a href="{% url catalogue %}#epoki"><span class='mono'>{% trans "Epochs" %}</span></a></li>
<li><a href="{% url catalogue %}#motywy"><span class='mono'>{% trans "Themes" %}</span></a></li>
+ <li><a href="{% url book_list %}"><span class='mono'>{% trans "All books" %}</span></a></li>
+ <li><a href="{% url audiobook_list %}"><span class='mono'>{% trans "Audiobooks" %}</span></a></li>
+ <li><a href="{% url daisy_list %}"><span class='mono'>{% trans "DAISY" %}</span></a></li>
</ul>
<form action="{% url django.views.i18n.set_language %}" method="post">
<div id="lang-menu">
- <span id='lang-button' class='mono-small'>
+ <span id='lang-button' class='mono'>
{% trans "Language versions" %}</span>
<div id="lang-menu-items">
{% for lang in LANGUAGES %}
<button type="submit" name="language"
- class="{% ifequal lang.0 LANGUAGE_CODE %}active{% endifequal %} {% if forloop.last %}last{% endif %}"
+ class="{% ifequal lang.0 LANGUAGE_CODE %}active{% endifequal %} mono"
value="{{ lang.0 }}">{{ lang.1 }}</button>
{% endfor %}
</div>
# Admin panel
url(r'^admin/catalogue/book/import$', 'catalogue.views.import_book', name='import_book'),
+ url(r'^admin/catalogue/picture/import$', 'picture.views.import_picture', name='import_picture'),
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', include(admin.site.urls)),
# API
(r'^api/', include('api.urls')),
+ url(r'^fullsearch/', include('search.urls')),
+
# Static files
url(r'^%s(?P<path>.*)$' % settings.MEDIA_URL[1:], 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),