Beispiel #1
0
 def getitem_es(self, key):
     """ Get item with ID of :key: from elasticsearch """
     from nefertari.elasticsearch import ES
     es = ES(self.__context_class__.__name__)
     pk_field = self.__context_class__.pk_field()
     kwargs = {
         pk_field: key,
         '_limit': 1,
         '__raise_on_empty': True,
     }
     obj = es.get_collection(**kwargs)[0]
     obj.__acl__ = self.context_acl(obj)
     obj.__parent__ = self
     obj.__name__ = key
     return obj
Beispiel #2
0
    def get_collection_es(self, **kwargs):
        """ Get ES objects collection taking into account the generated
        queryset of parent view.

        This method allows working with nested resources properly. Thus a
        queryset returned by this method will be a subset of its parent view's
        queryset, thus filtering out objects that don't belong to the parent
        object.
        """
        from nefertari.elasticsearch import ES
        es = ES(self.Model.__name__)
        objects_ids = self._parent_queryset_es()

        if objects_ids is not None:
            objects_ids = self.get_es_object_ids(objects_ids)

            if not objects_ids:
                return []
            self._query_params['id'] = objects_ids
        return es.get_collection(
            _raw_terms=self._get_raw_terms(),
            **self._query_params)