diff -r 62e994990709 -r 288173daa1ac apps/blog/search_indexes.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/blog/search_indexes.py Thu Dec 17 23:40:13 2009 +0100
@@ -0,0 +1,24 @@
+from django.conf import settings
+from datetime import datetime as dt
+from haystack import indexes
+from haystack import site
+from blog.models import Post
+
+def get_search_index_class():
+ if settings.HAYSTACK_SEARCH_AUTOUPDATE:
+ return indexes.RealTimeSearchIndex
+ else:
+ return indexes.SearchIndex
+
+class PostIndex(get_search_index_class()):
+ text = indexes.CharField(document=True, use_template=True)
+ name = indexes.CharField(model_attr='name')
+ body = indexes.CharField(model_attr='text')
+ date = indexes.DateField(model_attr='date')
+ is_draft = indexes.BooleanField(model_attr='is_draft')
+
+ def get_queryset(self):
+ return Post.objects.filter(date__lt=dt.now())
+
+site.register(Post, PostIndex)
+
diff -r 62e994990709 -r 288173daa1ac apps/search/__init__.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/search/__init__.py Thu Dec 17 23:40:13 2009 +0100
@@ -0,0 +1,4 @@
+import haystack
+
+haystack.autodiscover()
+
diff -r 62e994990709 -r 288173daa1ac apps/search/urls.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/search/urls.py Thu Dec 17 23:40:13 2009 +0100
@@ -0,0 +1,13 @@
+from datetime import datetime as dt
+from django.conf.urls.defaults import *
+from haystack.query import SearchQuerySet
+from haystack.views import SearchView
+
+sqs = SearchQuerySet().filter(date__lt=dt.now()).order_by('-date').filter(is_draft=False)
+
+urlpatterns = patterns('haystack.views',
+ url(r'^$', SearchView(
+ searchqueryset=sqs,
+ ), name='post_search'),
+)
+
diff -r 62e994990709 -r 288173daa1ac settings.py
--- a/settings.py Tue Dec 01 14:00:11 2009 +0200
+++ b/settings.py Thu Dec 17 23:40:13 2009 +0100
@@ -66,13 +66,13 @@ if not hasattr(globals(), 'SECRET_KEY'):
SECRET_KEY = open(SECRET_FILE).read().strip()
except IOError:
try:
- import string, random
- SECRET_KEY = ''.join(random.choice(string.printable) for i in xrange(50))
+ from random import choice
+ SECRET_KEY = ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)])
secret = file(SECRET_FILE, 'w')
secret.write(SECRET_KEY)
secret.close()
except IOError:
- raise Exception('Please create a %s file with random characters to set your secret key' % SECRET_FILE)
+ raise Exception('Please create a %s file with random characters to generate your secret key!' % SECRET_FILE)
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
@@ -145,6 +145,9 @@ INSTALLED_APPS = (
'openidconsumer',
'openidserver',
'revcanonical',
+ # 'tagging_autocomplete',
+ # 'haystack' # for search through posts, if this will
+ # be used update also haystack entries in settings_local.py
)
APPEND_SLASH = False
@@ -250,7 +253,7 @@ if not hasattr(globals(), 'THEME_STATIC_
THEME_STATIC_ROOT = os.path.join(STATIC_ROOT, THEME + '/')
if not hasattr(globals(), 'THEME_STATIC_URL'):
- THEME_STATIC_URL = os.path.join(STATIC_URL, THEME + '/')
+ THEME_STATIC_URL = STATIC_URL
try:
INSTALLED_APPS += ADDITIONAL_APPS
diff -r 62e994990709 -r 288173daa1ac settings_local.py.template
--- a/settings_local.py.template Tue Dec 01 14:00:11 2009 +0200
+++ b/settings_local.py.template Thu Dec 17 23:40:13 2009 +0100
@@ -75,6 +75,18 @@ LJ_USERNAME = ''
LJ_USERNAME = ''
LJ_PASSWORD = ''
+
+# haystack settings
+# set False if you have ./manage.py update_index in your cron tasks
+HAYSTACK_SEARCH_AUTOUPDATE = True
+HAYSTACK_SITECONF = 'apps.search' # don't change it
+HAYSTACK_SEARCH_RESULTS_PER_PAGE = 21
+HAYSTACK_SEARCH_ENGINE = 'whoosh' # whoosh | solr | xapian | dummy
+# see http://haystacksearch.org/docs/tutorial.html#configuration
+HAYSTACK_WHOOSH_PATH = ''
+HAYSTACK_SOLR_URL = ''
+HAYSTACK_XAPIAN_PATH = ''
+
# sape.ru settings
#SAPE_USER = '74947f25f25d6eb17e910005cbeaa8e6' # You sape.ru ID
# Links cache file. Check permissions!
diff -r 62e994990709 -r 288173daa1ac templates/search/indexes/blog/post_text.txt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/search/indexes/blog/post_text.txt Thu Dec 17 23:40:13 2009 +0100
@@ -0,0 +1,2 @@
+{{ object.text }}
+
diff -r 62e994990709 -r 288173daa1ac templates/search/search.html
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/search/search.html Thu Dec 17 23:40:13 2009 +0100
@@ -0,0 +1,36 @@
+{% extends "base.html" %}
+{% load i18n %}
+{% load highlight %}
+
+{% block title %}{% trans "Search results for:" %} {{ query }}{% endblock %}
+
+{% block content %}
+
+<h1>{% trans "Search results for:" %} {{ query }}</h1>
+
+{% if not page.object_list %}
+ <p>{% trans "No results found" %}</p>
+{% endif %}
+
+{% if page.object_list %}
+ <ul class="search_results_list">
+ {% for result in page.object_list %}
+ <li>
+ <strong><a href="{{ result.object.get_absolute_url }}">{{ result.name }}</a></strong><br/>
+ {% highlight result.body with query max_length 256 html_tag "span" %}
+ </li>
+ {% endfor %}
+ </ul>
+
+ <div class="pagination" style="float:right">
+ {% if page.has_previous %}
+ <a href="{{ base }}?q={{ query|urlencode }}&page={{ page.previous_page_number }}">« {% trans "Newer posts" %}</a>
+ {% endif %}
+ |
+ {% if page.has_next %}
+ <a href="{{ base }}?q={{ query|urlencode }}&page={{ page.next_page_number }}">{% trans "Older posts" %} »</a>
+ {% endif %}
+ </div>
+{% endif %}
+
+{% endblock %}
diff -r 62e994990709 -r 288173daa1ac urls.py
--- a/urls.py Tue Dec 01 14:00:11 2009 +0200
+++ b/urls.py Thu Dec 17 23:40:13 2009 +0100
@@ -52,6 +52,7 @@ urlpatterns += patterns(
url(r'^robots.txt$', include('robots.urls')),
url(r'^feeds/', include('feed.urls')),
url(r'^tagging_autocomplete/', include('tagging_autocomplete.urls')),
+ #url(r'^search/', include('search.urls')),
)
if appcheck.watchlist:
----------------------------------------------------------------------
Zbieraj punkty - wygrywaj nagrody!
Kliknij >>> http://link.interia.pl/f24a8
That looks wrong. It reverses a change I made when fixing
apps/lib/templatetags/theme.py . It could be that your settings.py
is just missing a merge from that change.
--
Ben Jackson AD7GD
<b...@ben.com>
http://www.ben.com/