Mercurial > public > sg101
annotate gpp/bio/search_indexes.py @ 562:98b373ca09f3
For bitbucket issue #3, ensure that changes to Profile, Post & Topic models
via the admin cause the search index to be updated.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 08 Feb 2012 18:58:57 -0600 |
parents | 387d46abcb95 |
children |
rev | line source |
---|---|
bgneal@223 | 1 """Haystack search index for the bio application.""" |
bgneal@223 | 2 from haystack.indexes import * |
bgneal@223 | 3 from haystack import site |
bgneal@469 | 4 from custom_search.indexes import CondQueuedSearchIndex |
bgneal@223 | 5 |
bgneal@223 | 6 from bio.models import UserProfile |
bgneal@471 | 7 from bio.signals import profile_content_update |
bgneal@223 | 8 |
bgneal@223 | 9 |
bgneal@467 | 10 class UserProfileIndex(CondQueuedSearchIndex): |
bgneal@223 | 11 text = CharField(document=True, use_template=True) |
bgneal@223 | 12 author = CharField(model_attr='user') |
bgneal@223 | 13 |
bgneal@533 | 14 def index_queryset(self): |
bgneal@223 | 15 return UserProfile.objects.filter(user__is_active=True) |
bgneal@223 | 16 |
bgneal@277 | 17 def get_updated_field(self): |
bgneal@277 | 18 return 'update_date' |
bgneal@277 | 19 |
bgneal@471 | 20 def _setup_save(self, model): |
bgneal@471 | 21 profile_content_update.connect(self.enqueue_save) |
bgneal@471 | 22 |
bgneal@471 | 23 def _teardown_save(self, model): |
bgneal@471 | 24 profile_content_update.disconnect(self.enqueue_save) |
bgneal@471 | 25 |
bgneal@471 | 26 def enqueue_save(self, sender, **kwargs): |
bgneal@471 | 27 return self.enqueue('update', sender) |
bgneal@471 | 28 |
bgneal@223 | 29 |
bgneal@223 | 30 site.register(UserProfile, UserProfileIndex) |