changeset 223:cd4124b19196

For #51; add user profiles to Haystack search.
author Brian Neal <bgneal@gmail.com>
date Mon, 07 Jun 2010 03:37:36 +0000
parents a5fcf3d1b663
children 76ad86454ce9
files gpp/bio/models.py gpp/bio/search_indexes.py gpp/templates/bio/members.html gpp/templates/search/indexes/bio/userprofile_text.txt
diffstat 4 files changed, 37 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/gpp/bio/models.py	Sun Jun 06 21:05:48 2010 +0000
+++ b/gpp/bio/models.py	Mon Jun 07 03:37:36 2010 +0000
@@ -127,6 +127,16 @@
     user_is_active.boolean = True
     user_is_active.short_description = "Is Active"
 
+    def search_title(self):
+        full_name = self.user.get_full_name()
+        if full_name:
+            return u"%s (%s)" % (self.user.username, full_name)
+        return self.user.username
+
+    def search_summary(self):
+        return u"\n".join((self.location, self.occupation, self.interests,
+            self.profile_text, self.signature))
+
 
 class UserProfileFlag(models.Model):
     """This model represents a user flagging a profile as inappropriate."""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gpp/bio/search_indexes.py	Mon Jun 07 03:37:36 2010 +0000
@@ -0,0 +1,16 @@
+"""Haystack search index for the bio application."""
+from haystack.indexes import *
+from haystack import site
+
+from bio.models import UserProfile
+
+
+class UserProfileIndex(SearchIndex):
+    text = CharField(document=True, use_template=True)
+    author = CharField(model_attr='user')
+
+    def get_queryset(self):
+        return UserProfile.objects.filter(user__is_active=True)
+
+
+site.register(UserProfile, UserProfileIndex)
--- a/gpp/templates/bio/members.html	Sun Jun 06 21:05:48 2010 +0000
+++ b/gpp/templates/bio/members.html	Mon Jun 07 03:37:36 2010 +0000
@@ -8,7 +8,10 @@
 {% block content %}
 <h2>Member List</h2>
 <p>Surfguitar101.com currently has {{ num_members }} active members. Looking for a
-particular user? Try our <a href="{% url bio-member_search %}">member search</a>.</p>
+particular user? Try our <a href="{% url bio-member_search %}">member search</a>, or
+you can use our <a href="{% url haystack_search %}">search function</a> to search
+user profiles.
+</p>
 {% if page.object_list %}
 <ul class="tab-nav">
    <li><a href="{% url bio-members_full type='user' page=1 %}"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gpp/templates/search/indexes/bio/userprofile_text.txt	Mon Jun 07 03:37:36 2010 +0000
@@ -0,0 +1,7 @@
+{{ object.user.username }}
+{{ object.user.get_full_name }}
+{{ object.location }}
+{{ object.occupation }}
+{{ object.interests }}
+{{ object.profile_text }}
+{{ object.signature }}