Ejemplo n.º 1
0
    def get_by_id(cls, context, id, *args, **kwargs):
        # To get by id we need to have a model and for the model to
        # have an id field
        if "id" not in cls.fields:
            msg = _("VersionedObject %s cannot retrieve object by id.") % (cls.obj_name())
            raise NotImplementedError(msg)

        model = db.get_model_for_versioned_object(cls)
        orm_obj = db.get_by_id(context, model, id, *args, **kwargs)
        kargs = {}
        if hasattr(cls, "DEFAULT_EXPECTED_ATTR"):
            kargs = {"expected_attrs": getattr(cls, "DEFAULT_EXPECTED_ATTR")}
        return cls._from_db_object(context, cls(context), orm_obj, **kargs)
Ejemplo n.º 2
0
    def get_by_id(cls, context, id, *args, **kwargs):
        # To get by id we need to have a model and for the model to
        # have an id field
        if 'id' not in cls.fields:
            msg = (_('VersionedObject %s cannot retrieve object by id.') %
                   (cls.obj_name()))
            raise NotImplementedError(msg)

        model = db.get_model_for_versioned_object(cls)
        orm_obj = db.get_by_id(context, model, id, *args, **kwargs)
        kargs = {}
        if hasattr(cls, 'DEFAULT_EXPECTED_ATTR'):
            kargs = {'expected_attrs': getattr(cls, 'DEFAULT_EXPECTED_ATTR')}
        return cls._from_db_object(context, cls(context), orm_obj, **kargs)
Ejemplo n.º 3
0
    def get_by_id(cls, context, id, *args, **kwargs):
        # To get by id we need to have a model and for the model to
        # have an id field
        if 'id' not in cls.fields:
            msg = (_('VersionedObject %s cannot retrieve object by id.') %
                   (cls.obj_name()))
            raise NotImplementedError(msg)

        orm_obj = db.get_by_id(context, cls.model, id, *args, **kwargs)
        # We pass parameters because fields to expect may depend on them
        expected_attrs = cls._get_expected_attrs(context, *args, **kwargs)
        kargs = {}
        if expected_attrs:
            kargs = {'expected_attrs': expected_attrs}
        return cls._from_db_object(context, cls(context), orm_obj, **kargs)
Ejemplo n.º 4
0
    def get_by_id(cls, context, id, *args, **kwargs):
        # To get by id we need to have a model and for the model to
        # have an id field
        if 'id' not in cls.fields:
            msg = (_('VersionedObject %s cannot retrieve object by id.') %
                   (cls.obj_name()))
            raise NotImplementedError(msg)

        model = db.get_model_for_versioned_object(cls)
        orm_obj = db.get_by_id(context, model, id, *args, **kwargs)
        expected_attrs = cls._get_expected_attrs(context)
        kargs = {}
        if expected_attrs:
            kargs = {'expected_attrs': expected_attrs}
        return cls._from_db_object(context, cls(context), orm_obj, **kargs)
Ejemplo n.º 5
0
    def get_by_id(cls, context, id, *args, **kwargs):
        # To get by id we need to have a model and for the model to
        # have an id field
        if "id" not in cls.fields:
            msg = _("VersionedObject %s cannot retrieve object by id.") % (cls.obj_name())
            raise NotImplementedError(msg)

        orm_obj = db.get_by_id(context, cls.model, id, *args, **kwargs)
        expected_attrs = cls._get_expected_attrs(context)
        # We pass parameters because fields to expect may depend on them
        expected_attrs = cls._get_expected_attrs(context, *args, **kwargs)
        kargs = {}
        if expected_attrs:
            kargs = {"expected_attrs": expected_attrs}
        return cls._from_db_object(context, cls(context), orm_obj, **kargs)