]> git.parisson.com Git - telemeta.git/commitdiff
init first haystack tests
authorGuillaume Pellerin <yomguy@parisson.com>
Wed, 11 Mar 2015 20:56:51 +0000 (21:56 +0100)
committerGuillaume Pellerin <yomguy@parisson.com>
Wed, 11 Mar 2015 20:56:51 +0000 (21:56 +0100)
example/sandbox/settings.py
telemeta/models/search_indexes.py [new file with mode: 0644]
telemeta/templates/search/search.html [new file with mode: 0644]
telemeta/urls.py

index 4f469f5a49c337de0d11b980bb2b491446c2c05f..05725e4455645a00108e4b530a0ac538a407e368 100644 (file)
@@ -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 (file)
index 0000000..cbd4bb2
--- /dev/null
@@ -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 (file)
index 0000000..e3f6dd4
--- /dev/null
@@ -0,0 +1,39 @@
+{% extends 'telemeta/base.html' %}
+
+{% block content %}
+    <h2>Search</h2>
+
+    <form method="get" action=".">
+        <table>
+            {{ form.as_table }}
+            <tr>
+                <td>&nbsp;</td>
+                <td>
+                    <input type="submit" value="Search">
+                </td>
+            </tr>
+        </table>
+
+        {% if query %}
+            <h3>Results</h3>
+
+            {% for result in page.object_list %}
+                <p>
+                    <a href="{{ result.object.get_absolute_url }}">{{ result.object.title }}</a>
+                </p>
+            {% empty %}
+                <p>No results found.</p>
+            {% endfor %}
+
+            {% if page.has_previous or page.has_next %}
+                <div>
+                    {% if page.has_previous %}<a href="?q={{ query }}&amp;page={{ page.previous_page_number }}">{% endif %}&laquo; Previous{% if page.has_previous %}</a>{% endif %}
+                    |
+                    {% if page.has_next %}<a href="?q={{ query }}&amp;page={{ page.next_page_number }}">{% endif %}Next &raquo;{% if page.has_next %}</a>{% endif %}
+                </div>
+            {% endif %}
+        {% else %}
+            {# Show some example queries to run, maybe query syntax, something else? #}
+        {% endif %}
+    </form>
+{% endblock %}
\ No newline at end of file
index 8550588b4ef74f1240eec4718968ce3c606f3a05..cac3461a288a41e13472c80e08211e35acfe8737 100644 (file)
@@ -142,6 +142,7 @@ urlpatterns = patterns('',
     url(r'^search/(?P<type>[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"),