annotate forums/search_indexes.py @ 623:1555b2c3c7a0

For issue #22, add a UNIQUE contraint on the pending user table's username field.
author Brian Neal <bgneal@gmail.com>
date Wed, 31 Oct 2012 20:06:01 -0500
parents ee87ea74d46b
children ad53d929281a
rev   line source
bgneal@222 1 """Haystack search index for the weblinks application."""
bgneal@222 2 from haystack.indexes import *
bgneal@222 3 from haystack import site
bgneal@469 4 from custom_search.indexes import CondQueuedSearchIndex
bgneal@222 5
bgneal@414 6 from forums.models import Forum, Topic, Post
bgneal@469 7 from forums.signals import topic_content_update, post_content_update
bgneal@414 8
bgneal@414 9
bgneal@467 10 class TopicIndex(CondQueuedSearchIndex):
bgneal@414 11 text = CharField(document=True, use_template=True)
bgneal@414 12 author = CharField(model_attr='user')
bgneal@414 13 pub_date = DateTimeField(model_attr='creation_date')
bgneal@414 14
bgneal@533 15 def index_queryset(self):
bgneal@414 16 return Topic.objects.filter(forum__in=Forum.objects.public_forum_ids())
bgneal@414 17
bgneal@414 18 def get_updated_field(self):
bgneal@414 19 return 'update_date'
bgneal@222 20
bgneal@469 21 def _setup_save(self, model):
bgneal@469 22 topic_content_update.connect(self.enqueue_save)
bgneal@469 23
bgneal@469 24 def _teardown_save(self, model):
bgneal@469 25 topic_content_update.disconnect(self.enqueue_save)
bgneal@469 26
bgneal@470 27 def enqueue_save(self, sender, **kwargs):
bgneal@470 28 return self.enqueue('update', sender)
bgneal@470 29
bgneal@467 30 def can_index(self, instance):
bgneal@467 31 return instance.forum.id in Forum.objects.public_forum_ids()
bgneal@222 32
bgneal@467 33
bgneal@467 34 class PostIndex(CondQueuedSearchIndex):
bgneal@222 35 text = CharField(document=True, use_template=True)
bgneal@222 36 author = CharField(model_attr='user')
bgneal@222 37 pub_date = DateTimeField(model_attr='creation_date')
bgneal@222 38
bgneal@533 39 def index_queryset(self):
bgneal@222 40 return Post.objects.filter(
bgneal@414 41 topic__forum__in=Forum.objects.public_forum_ids())
bgneal@222 42
bgneal@277 43 def get_updated_field(self):
bgneal@277 44 return 'update_date'
bgneal@277 45
bgneal@469 46 def _setup_save(self, model):
bgneal@469 47 post_content_update.connect(self.enqueue_save)
bgneal@469 48
bgneal@469 49 def _teardown_save(self, model):
bgneal@469 50 post_content_update.disconnect(self.enqueue_save)
bgneal@469 51
bgneal@470 52 def enqueue_save(self, sender, **kwargs):
bgneal@470 53 return self.enqueue('update', sender)
bgneal@470 54
bgneal@467 55 def can_index(self, instance):
bgneal@467 56 return instance.topic.forum.id in Forum.objects.public_forum_ids()
bgneal@467 57
bgneal@222 58
bgneal@414 59 site.register(Topic, TopicIndex)
bgneal@222 60 site.register(Post, PostIndex)