Mercurial > public > sg101
annotate forums/search_indexes.py @ 849:ff645a692791
For issue #79, use bleach to sanitize both user input markdown & html.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 30 Oct 2014 19:30:37 -0500 |
parents | ad53d929281a |
children | cf9918328c64 |
rev | line source |
---|---|
bgneal@222 | 1 """Haystack search index for the weblinks application.""" |
bgneal@753 | 2 from haystack import indexes |
bgneal@222 | 3 |
bgneal@414 | 4 from forums.models import Forum, Topic, Post |
bgneal@414 | 5 |
bgneal@414 | 6 |
bgneal@753 | 7 class TopicIndex(indexes.SearchIndex, indexes.Indexable): |
bgneal@753 | 8 text = indexes.CharField(document=True, use_template=True) |
bgneal@753 | 9 author = indexes.CharField(model_attr='user') |
bgneal@753 | 10 pub_date = indexes.DateTimeField(model_attr='creation_date') |
bgneal@414 | 11 |
bgneal@753 | 12 def get_model(self): |
bgneal@753 | 13 return Topic |
bgneal@753 | 14 |
bgneal@753 | 15 def index_queryset(self, using=None): |
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 |
bgneal@753 | 22 class PostIndex(indexes.SearchIndex, indexes.Indexable): |
bgneal@753 | 23 text = indexes.CharField(document=True, use_template=True) |
bgneal@753 | 24 author = indexes.CharField(model_attr='user') |
bgneal@753 | 25 pub_date = indexes.DateTimeField(model_attr='creation_date') |
bgneal@469 | 26 |
bgneal@753 | 27 def get_model(self): |
bgneal@753 | 28 return Post |
bgneal@470 | 29 |
bgneal@753 | 30 def index_queryset(self, using=None): |
bgneal@222 | 31 return Post.objects.filter( |
bgneal@414 | 32 topic__forum__in=Forum.objects.public_forum_ids()) |
bgneal@222 | 33 |
bgneal@277 | 34 def get_updated_field(self): |
bgneal@277 | 35 return 'update_date' |