コード例 #1
0
ファイル: models.py プロジェクト: ChiPyMozillaSprint/kitsune
        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(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:
コード例 #2
0
ファイル: models.py プロジェクト: rootmeb/kitsune
    def extract_document(cls, obj_id, obj=None):
        """Extracts indexable attributes from an Answer."""
        fields = ['id', 'created', 'user_id', 'locale']

        if obj is None:
            model = cls.get_model()
            obj_dict = model.objects.values(*fields).get(pk=obj_id)
        else:
            obj_dict = dict((field, getattr(obj, field)) for field in fields)

        d = {}
        d['id'] = obj_dict['id']
        d['model'] = cls.get_mapping_type_name()

        d['indexed_on'] = int(time.time())

        d['created'] = obj_dict['created']

        d['locale'] = obj_dict['locale']
        d['creator_id'] = obj_dict['user_id']

        return d


register_for_indexing('replies', Reply)
# Also update the creator in the users index.
register_for_indexing('users',
                      Reply,
                      instance_to_indexee=(lambda i: get_profile(i.user)
                                           if i.user else None))
コード例 #3
0
ファイル: models.py プロジェクト: MikkCZ/kitsune
                                   .values_list('content',
                                                'creator__username'))

        d['question_answer_content'] = [a[0] for a in answer_values]
        d['question_answer_creator'] = list(set(a[1] for a in answer_values))

        if not answer_values:
            d['question_has_helpful'] = False
        else:
            d['question_has_helpful'] = Answer.objects.filter(
                question=obj_id).filter(votes__helpful=True).exists()

        return d


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)))


def _tag_added(sender, question_id, tag_name, **kwargs):
    """Signal handler for new tag on question."""
    if tag_name == config.ESCALATE_TAG_NAME:
        escalate_question.delay(question_id)
tag_added.connect(_tag_added, sender=Question, dispatch_uid='tagged_1337')

コード例 #4
0
ファイル: models.py プロジェクト: shuhaowu/kitsune
        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"""
コード例 #5
0
ファイル: models.py プロジェクト: RobbyGenius73/kitsune
        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"""
コード例 #6
0
                                   .values_list('content',
                                                'creator__username'))

        d['question_answer_content'] = [a[0] for a in answer_values]
        d['question_answer_creator'] = list(set(a[1] for a in answer_values))

        if not answer_values:
            d['question_has_helpful'] = False
        else:
            d['question_has_helpful'] = Answer.objects.filter(
                question=obj_id).filter(votes__helpful=True).exists()

        return d


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)))


def _tag_added(sender, question_id, tag_name, **kwargs):
    """Signal handler for new tag on question."""
    if tag_name == config.ESCALATE_TAG_NAME:
        escalate_question.delay(question_id)
tag_added.connect(_tag_added, sender=Question, dispatch_uid='tagged_1337')

コード例 #7
0
ファイル: models.py プロジェクト: akatsoulas/kitsune
        results = es.suggest(index=cls.get_index(), body={
            USER_SUGGEST: {
                'text': text.lower(),
                'completion': {
                    'field': 'suggest'
                }
            }
        })

        if results[USER_SUGGEST][0]['length'] > 0:
            return results[USER_SUGGEST][0]['options']

        return []


register_for_indexing('users', Profile)


def get_profile(u):
    try:
        return Profile.objects.get(user=u)
    except Profile.DoesNotExist:
        return None


register_for_indexing(
    'users',
    User,
    instance_to_indexee=get_profile)

コード例 #8
0
ファイル: models.py プロジェクト: GVRV/kitsune
                                   .values_list('content',
                                                'creator__username'))

        d['question_answer_content'] = [a[0] for a in answer_values]
        d['question_answer_creator'] = list(set(a[1] for a in answer_values))

        if not answer_values:
            d['question_has_helpful'] = False
        else:
            d['question_has_helpful'] = Answer.objects.filter(
                question=obj_id).filter(votes__helpful=True).exists()

        return d


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)
コード例 #9
0
ファイル: models.py プロジェクト: timbury/kitsune
        content = []

        posts = Post.objects.filter(thread_id=obj.id).select_related('author')
        for post in posts:
            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(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)
    flags = generic.GenericRelation(FlaggedObject)
コード例 #10
0
ファイル: models.py プロジェクト: SuperBumbum777/kitsune
            cls.get_index(), {
                USER_SUGGEST: {
                    'text': text.lower(),
                    'completion': {
                        'field': 'suggest'
                    }
                }
            })

        if results[USER_SUGGEST][0]['length'] > 0:
            return results[USER_SUGGEST][0]['options']

        return []


register_for_indexing('users', Profile)


def _get_profile(u):
    try:
        return u.get_profile()
    except Profile.DoesNotExist:
        return None


register_for_indexing('users',
                      User,
                      instance_to_indexee=(lambda u: _get_profile(u)))


class Setting(ModelBase):
コード例 #11
0
ファイル: models.py プロジェクト: warejohn/kitsune
                             body={
                                 USER_SUGGEST: {
                                     'text': text.lower(),
                                     'completion': {
                                         'field': 'suggest'
                                     }
                                 }
                             })

        if results[USER_SUGGEST][0]['length'] > 0:
            return results[USER_SUGGEST][0]['options']

        return []


register_for_indexing('users', Profile)


def get_profile(u):
    try:
        return Profile.objects.get(user=u)
    except Profile.DoesNotExist:
        return None


register_for_indexing('users', User, instance_to_indexee=get_profile)


class Setting(ModelBase):
    """User specific value per setting"""
    user = models.ForeignKey(User,
コード例 #12
0
ファイル: models.py プロジェクト: doismellburning/kitsune
        results = es.suggest(cls.get_index(), {
            USER_SUGGEST : {
                'text': text.lower(),
                'completion' : {
                    'field' : 'suggest'
                }
            }
        })

        if results[USER_SUGGEST][0]['length'] > 0:
            return results[USER_SUGGEST][0]['options']

        return []


register_for_indexing('users', Profile)


def _get_profile(u):
    try:
        return u.get_profile()
    except Profile.DoesNotExist:
        return None


register_for_indexing(
    'users',
    User,
    instance_to_indexee=(
        lambda u: _get_profile(u)))
コード例 #13
0
ファイル: models.py プロジェクト: thelegend6420/kitsune
            Answer.uncached.filter(question=obj_id).values_list(
                'content', 'creator__username'))

        d['question_answer_content'] = [a[0] for a in answer_values]
        d['question_answer_creator'] = list(set(a[1] for a in answer_values))

        if not answer_values:
            d['question_has_helpful'] = False
        else:
            d['question_has_helpful'] = Answer.objects.filter(
                question=obj_id).filter(votes__helpful=True).exists()

        return d


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)


def _tag_added(sender, question_id, tag_name, **kwargs):
    """Signal handler for new tag on question."""
    if tag_name == config.ESCALATE_TAG_NAME:
        escalate_question.delay(question_id)
コード例 #14
0
ファイル: models.py プロジェクト: SuperBumbum777/kitsune
        }

    @classmethod
    def extract_document(cls, obj_id, obj=None):
        """Extracts indexable attributes from an Answer."""
        fields = ['id', 'created', 'user_id', 'locale']

        if obj is None:
            model = cls.get_model()
            obj_dict = model.uncached.values(*fields).get(pk=obj_id)
        else:
            obj_dict = dict([(field, getattr(obj, field))
                              for field in fields])

        d = {}
        d['id'] = obj_dict['id']
        d['model'] = cls.get_mapping_type_name()

        d['indexed_on'] = int(time.time())

        d['created'] = obj_dict['created']

        d['locale'] = obj_dict['locale']
        d['creator_id'] = obj_dict['user_id']

        return d


register_for_indexing('replies', Reply)

コード例 #15
0
ファイル: models.py プロジェクト: 1234-/kitsune
        fields = ['id', 'created', 'user_id', 'locale']

        if obj is None:
            model = cls.get_model()
            obj_dict = model.objects.values(*fields).get(pk=obj_id)
        else:
            obj_dict = dict((field, getattr(obj, field))
                            for field in fields)

        d = {}
        d['id'] = obj_dict['id']
        d['model'] = cls.get_mapping_type_name()

        d['indexed_on'] = int(time.time())

        d['created'] = obj_dict['created']

        d['locale'] = obj_dict['locale']
        d['creator_id'] = obj_dict['user_id']

        return d


register_for_indexing('replies', Reply)
# Also update the creator in the users index.
register_for_indexing(
    'users',
    Reply,
    instance_to_indexee=(
        lambda i: get_profile(i.user) if i.user else None))