def registration_hook(self, cls, index): setattr(objects, cls.obj_name(), cls) # For Versioned Object Classes that have a model store the model in # a Class attribute named model try: cls.model = db.get_model_for_versioned_object(cls) except (ImportError, AttributeError): pass
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)