Beispiel #1
0
 def get_by_user_id(cls, user_id, obj_id):
     """Get a core object belong to user, with model related id."""
     param = {cls._pkey_name: obj_id}
     obj = cls._model_class.get(user_id=user_id, **param)
     if obj:
         return cls(obj)
     raise NotFound('%s #%s not found for user %s' %
                    (cls.__class__.name, obj_id, user_id))
Beispiel #2
0
 def get_db(self, **options):
     """Get a core object from database and put it in self._db attribute"""
     if self._pkey_name:
         param = {self._pkey_name: getattr(self, self._pkey_name)}
     else:
         param = {}
     self._db = self._model_class.get(**param)
     if self._db is None:
         raise NotFound(
             '%s #%s not found.' %
             (self.__class__.__name__, getattr(self, self._pkey_name)))
Beispiel #3
0
    def get_db(self, **options):
        """Get an object belonging to an user and put it in self._db attrs"""
        if self._pkey_name:
            param = {self._pkey_name: getattr(self, self._pkey_name)}
        else:
            param = {}

        self._db = self._model_class.get(user_id=self.user_id, **param)
        if self._db is None:
            raise NotFound('%s #%s not found for user %s' %
                           (self.__class__.__name__, param[self._pkey_name],
                            self.user_id))
Beispiel #4
0
    def get_index(self, **options):
        """Get a doc from ES within user's index and put it at self._index"""

        obj_id = getattr(self, self._pkey_name)
        try:
            self._index = self._index_class.get(
                index=self.user_id,
                id=obj_id,
                using=self._index_class.client())
        except Exception as exc:
            if isinstance(exc, ESexceptions.NotFoundError):
                log.info("indexed doc not found")
                self._index = None
                raise NotFound('%s #%s not found for user %s' %
                               (self.__class__.__name__, obj_id, self.user_id))
            else:
                raise exc