From: Guillaume Pellerin Date: Wed, 11 Mar 2015 20:56:51 +0000 (+0100) Subject: init first haystack tests X-Git-Tag: 1.6a^2~18^2~8 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=63676c0b994fb4ce17cd0585ad4008f9e6d301e2;p=telemeta.git init first haystack tests --- diff --git a/example/sandbox/settings.py b/example/sandbox/settings.py index 4f469f5a..05725e44 100644 --- a/example/sandbox/settings.py +++ b/example/sandbox/settings.py @@ -149,6 +149,7 @@ INSTALLED_APPS = ( 'bootstrap_pagination', 'googletools', 'registration', + 'haystack', ) TEMPLATE_CONTEXT_PROCESSORS = ( @@ -257,3 +258,13 @@ SUIT_CONFIG = { # }, # }, # } + + +HAYSTACK_CONNECTIONS = { + 'default': { + 'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine', + 'URL': 'http://127.0.0.1:9200/', + 'INDEX_NAME': 'haystack', + }, +} + diff --git a/telemeta/models/search_indexes.py b/telemeta/models/search_indexes.py new file mode 100644 index 00000000..cbd4bb2d --- /dev/null +++ b/telemeta/models/search_indexes.py @@ -0,0 +1,10 @@ +from haystack import indexes +from telemeta.models import * + + +class MediaItemIndex(indexes.SearchIndex, indexes.Indexable): + + title = indexes.CharField(use_template=True, document=True) + + def get_model(self): + return MediaItem diff --git a/telemeta/templates/search/search.html b/telemeta/templates/search/search.html new file mode 100644 index 00000000..e3f6dd4d --- /dev/null +++ b/telemeta/templates/search/search.html @@ -0,0 +1,39 @@ +{% extends 'telemeta/base.html' %} + +{% block content %} +

Search

+ +
+ + {{ form.as_table }} + + + + +
  + +
+ + {% if query %} +

Results

+ + {% for result in page.object_list %} +

+ {{ result.object.title }} +

+ {% empty %} +

No results found.

+ {% endfor %} + + {% if page.has_previous or page.has_next %} +
+ {% if page.has_previous %}{% endif %}« Previous{% if page.has_previous %}{% endif %} + | + {% if page.has_next %}{% endif %}Next »{% if page.has_next %}{% endif %} +
+ {% endif %} + {% else %} + {# Show some example queries to run, maybe query syntax, something else? #} + {% endif %} +
+{% endblock %} \ No newline at end of file diff --git a/telemeta/urls.py b/telemeta/urls.py index 8550588b..cac3461a 100644 --- a/telemeta/urls.py +++ b/telemeta/urls.py @@ -142,6 +142,7 @@ urlpatterns = patterns('', url(r'^search/(?P[A-Za-z0-9._-]+)/$', SearchView.as_view(), name="telemeta-search-type"), url(r'^search_criteria/$', home_view.edit_search, name="telemeta-search-criteria"), url(r'^complete_location/$', home_view.complete_location, name="telemeta-complete-location"), + url(r'^search_haystack/', include('haystack.urls')), # administration url(r'^admin/$', admin_view.admin_index, name="telemeta-admin"),