author_ords = set() content = [] for post in self.post_set.all(): author_ids.add(post.author.id) author_ords.add(post.author.username) content.append(post.content) d['author_id'] = list(author_ids) d['author_ord'] = list(author_ords) d['content'] = content return d register_for_indexing(Thread, 'forums') class Post(ActionMixin, ModelBase): thread = models.ForeignKey('Thread') content = models.TextField() author = models.ForeignKey(User) created = models.DateTimeField(default=datetime.datetime.now, db_index=True) updated = models.DateTimeField(default=datetime.datetime.now, db_index=True) updated_by = models.ForeignKey(User, related_name='post_last_updated_by', null=True) class Meta:
if (document['document_current_id'] is None or document['document_content'].startswith(REDIRECT_HTML)): cls.unindex(document['id'], es=kwargs.get('es', None)) return super(cls, cls).index(document, **kwargs) @classmethod def search(cls): s = super(Document, cls).search() return (s.query_fields('document_title__text', 'document_content__text', 'document_summary__text', 'document_keywords__text')) register_for_indexing(Document, 'wiki') register_for_indexing( TaggedItem, 'wiki', instance_to_indexee=( lambda i: i.content_object if isinstance(i.content_object, Document) else None)) class Revision(ModelBase): """A revision of a localized knowledgebase document""" document = models.ForeignKey(Document, related_name='revisions') summary = models.TextField() # wiki markup content = models.TextField() # wiki markup # Keywords are used mostly to affect search rankings. Moderators may not
d['indexed_on'] = int(time.time()) return d @classmethod def search(cls): s = super(Question, cls).search() return (s.query_fields('title__text', 'question_content__text', 'answer_content__text') .weight(title=4, question_content=3, answer_content=3) .highlight(before_match='<b>', after_match='</b>', limit=settings.SEARCH_SUMMARY_LENGTH)) register_for_indexing(Question, 'questions') register_for_indexing( TaggedItem, 'questions', instance_to_indexee=( lambda i: i.content_object if isinstance(i.content_object, Question) else None)) class QuestionMetaData(ModelBase): """Metadata associated with a support question.""" question = models.ForeignKey('Question', related_name='metadata_set') name = models.SlugField(db_index=True) value = models.TextField() class Meta:
qs = cls.objects.filter(created__gt=start, creator__is_active=True) return qs.count() @classmethod def recent_unanswered_count(cls): """Returns the number of questions that have not been answered in the last 72 hours """ start = datetime.now() - timedelta(hours=72) qs = cls.objects.filter( num_answers=0, created__gt=start, is_locked=False, creator__is_active=1) return qs.count() register_for_indexing('questions', Question) register_for_indexing( 'questions', TaggedItem, instance_to_indexee=( lambda i: i.content_object if isinstance(i.content_object, Question) else None)) register_for_indexing( 'questions', Question.topics.through, m2m=True) register_for_indexing( 'questions', Question.products.through, m2m=True)
if (document['document_current_id'] is None or document['document_content'].startswith(REDIRECT_HTML)): cls.unindex(document['id'], es=kwargs.get('es', None)) return super(cls, cls).index(document, **kwargs) @classmethod def search(cls): s = super(Document, cls).search() return (s.query_fields('document_title__text', 'document_content__text', 'document_summary__text', 'document_keywords__text')) register_for_indexing(Document, 'wiki') register_for_indexing( Document.topics.through, 'wiki', instance_to_indexee=lambda i: i, m2m=True) register_for_indexing( Document.products.through, 'wiki', instance_to_indexee=lambda i: i, m2m=True) class Revision(ModelBase): """A revision of a localized knowledgebase document""" document = models.ForeignKey(Document, related_name='revisions')
author_ids.add(post.author.id) author_ords.add(post.author.username) content.append(post.content) d['post_author_id'] = list(author_ids) d['post_author_ord'] = list(author_ords) d['post_content'] = content return d @classmethod def search(cls): return super(Thread, cls).search().order_by('created') register_for_indexing('forums', Thread) class Post(ActionMixin, ModelBase): thread = models.ForeignKey('Thread') content = models.TextField() author = models.ForeignKey(User) created = models.DateTimeField(default=datetime.datetime.now, db_index=True) updated = models.DateTimeField(default=datetime.datetime.now, db_index=True) updated_by = models.ForeignKey(User, related_name='post_last_updated_by', null=True) class Meta:
author_ords = set() content = [] for post in obj.post_set.select_related('author').all(): author_ids.add(post.author.id) author_ords.add(post.author.username) content.append(post.content) d['post_author_id'] = list(author_ids) d['post_author_ord'] = list(author_ords) d['post_content'] = content return d register_for_indexing('forums', Thread) class Post(ActionMixin, ModelBase): thread = models.ForeignKey('Thread') content = models.TextField() author = models.ForeignKey(User) created = models.DateTimeField(default=datetime.datetime.now, db_index=True) updated = models.DateTimeField(default=datetime.datetime.now, db_index=True) updated_by = models.ForeignKey(User, related_name='post_last_updated_by', null=True) class Meta:
document['document_content'].startswith(REDIRECT_HTML)): cls.unindex(document['id'], es=kwargs.get('es', None)) return super(cls, cls).index(document, **kwargs) @classmethod def search(cls): s = super(Document, cls).search() return (s.query_fields('document_title__text', 'document_content__text', 'document_summary__text', 'document_keywords__text')) register_for_indexing(Document, 'wiki') register_for_indexing( Document.topics.through, 'wiki', instance_to_indexee=lambda i: i, m2m=True) register_for_indexing( Document.products.through, 'wiki', instance_to_indexee=lambda i: i, m2m=True) class Revision(ModelBase): """A revision of a localized knowledgebase document""" document = models.ForeignKey(Document, related_name='revisions')
d["tag"] = list(TaggedItem.tags_for(Question, Question(pk=obj_id)).values_list("name", flat=True)) answer_values = list(Answer.objects.filter(question=obj_id).values_list("content", "creator__username")) d["answer_content"] = [a[0] for a in answer_values] d["answer_creator"] = list(set([a[1] for a in answer_values])) if not answer_values: d["has_helpful"] = False else: d["has_helpful"] = Answer.objects.filter(question=obj_id).filter(votes__helpful=True).exists() return d register_for_indexing(Question, "questions") register_for_indexing( TaggedItem, "questions", instance_to_indexee=lambda i: i.content_object if isinstance(i.content_object, Question) else None, ) class QuestionMetaData(ModelBase): """Metadata associated with a support question.""" question = models.ForeignKey("Question", related_name="metadata_set") name = models.SlugField(db_index=True) value = models.TextField() class Meta:
content.append(post.content) d['post_author_id'] = list(author_ids) d['post_author_ord'] = list(author_ords) d['post_content'] = content return d @classmethod def search(cls): s = super(Thread, cls).search() return (s.query_fields('post_title__text', 'post_content__text').order_by('created')) register_for_indexing(Thread, 'forums') class Post(ActionMixin, ModelBase): thread = models.ForeignKey('Thread') content = models.TextField() author = models.ForeignKey(User) created = models.DateTimeField(default=datetime.datetime.now, db_index=True) updated = models.DateTimeField(default=datetime.datetime.now, db_index=True) updated_by = models.ForeignKey(User, related_name='post_last_updated_by', null=True) class Meta:
indexable = indexable.filter(current_revision__isnull=False) return indexable @classmethod def index(cls, document, **kwargs): # If there are no revisions or the current revision is a # redirect, we want to remove it from the index. if (document['document_current_id'] is None or document['document_content'].startswith(REDIRECT_HTML)): cls.unindex(document['id'], es=kwargs.get('es', None)) return super(cls, cls).index(document, **kwargs) register_for_indexing('wiki', Document) register_for_indexing( 'wiki', Document.topics.through, m2m=True) register_for_indexing( 'wiki', Document.products.through, m2m=True) MAX_REVISION_COMMENT_LENGTH = 255 class Revision(ModelBase): """A revision of a localized knowledgebase document"""
@classmethod def recent_unanswered_count(cls, extra_filter=None): """Returns the number of questions that have not been answered in the last 24 hours. """ start = datetime.now() - timedelta(hours=24) qs = cls.objects.filter( num_answers=0, created__gt=start, is_locked=False, creator__is_active=1) if extra_filter: qs = qs.filter(extra_filter) return qs.count() register_for_indexing('questions', Question) register_for_indexing( 'questions', TaggedItem, instance_to_indexee=( lambda i: i.content_object if isinstance(i.content_object, Question) else None)) register_for_indexing( 'questions', Question.topics.through, m2m=True) register_for_indexing( 'questions', Question.products.through, m2m=True)