From 26ab7ce44ce29371f1c8e319ed6f707cefaef760 Mon Sep 17 00:00:00 2001
From: Correl Roush <correl@gmail.com>
Date: Thu, 6 Jan 2011 00:06:48 -0500
Subject: [PATCH] Added (ugly) commit search

---
 dashboard/search_indexes.py                   |  8 +++++
 .../search/includes/dashboard/commit.html     |  2 ++
 .../search/indexes/dashboard/commit_text.txt  |  3 ++
 templates/search/search.html                  | 34 +++++++++++++++++++
 urls.py                                       |  2 ++
 5 files changed, 49 insertions(+)
 create mode 100644 dashboard/search_indexes.py
 create mode 100644 templates/search/includes/dashboard/commit.html
 create mode 100644 templates/search/indexes/dashboard/commit_text.txt
 create mode 100644 templates/search/search.html

diff --git a/dashboard/search_indexes.py b/dashboard/search_indexes.py
new file mode 100644
index 0000000..1244648
--- /dev/null
+++ b/dashboard/search_indexes.py
@@ -0,0 +1,8 @@
+from haystack.indexes import *
+from haystack import site
+from codereview.dashboard.models import Commit
+
+class CommitIndex(SearchIndex):
+    text = CharField(document=True, use_template=True)
+
+site.register(Commit, CommitIndex)
diff --git a/templates/search/includes/dashboard/commit.html b/templates/search/includes/dashboard/commit.html
new file mode 100644
index 0000000..3801305
--- /dev/null
+++ b/templates/search/includes/dashboard/commit.html
@@ -0,0 +1,2 @@
+<dt>Commit: <a href="{% url codereview.browser.views.commit repository=result.object.repository.name ref=result.object.ref %}">{{ result.object.ref }}</a></dt>
+<dd>{{ result.object.message }}</dt>
diff --git a/templates/search/indexes/dashboard/commit_text.txt b/templates/search/indexes/dashboard/commit_text.txt
new file mode 100644
index 0000000..f2a2b33
--- /dev/null
+++ b/templates/search/indexes/dashboard/commit_text.txt
@@ -0,0 +1,3 @@
+{{ commit.author }}
+{{ commit.committer }}
+{{ commit.message }}
diff --git a/templates/search/search.html b/templates/search/search.html
new file mode 100644
index 0000000..f87c82a
--- /dev/null
+++ b/templates/search/search.html
@@ -0,0 +1,34 @@
+{% extends 'layouts/default.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 %}
+                {% if result.content_type == 'dashboard.commit' %}
+                    {% include 'search/includes/dashboard/commit.html' %}
+                {% endif %}
+            {% 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 %}
diff --git a/urls.py b/urls.py
index 9194ee5..cc59480 100755
--- a/urls.py
+++ b/urls.py
@@ -13,6 +13,8 @@ urlpatterns = patterns('',
     (r'^dashboard/', include('codereview.dashboard.urls')),
     (r'^review/', include('codereview.review.urls')),
 
+    (r'^search/', include('haystack.urls')),
+
     # Uncomment the admin/doc line below and add 'django.contrib.admindocs' 
     # to INSTALLED_APPS to enable admin documentation:
     # (r'^admin/doc/', include('django.contrib.admindocs.urls')),