Example #1
0
        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))
Example #2
0
    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))
Example #3
0
        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)
# 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))