
Untitled
By: a guest on
Aug 8th, 2012 | syntax:
None | size: 1.03 KB | hits: 10 | expires: Never
class EntityFactory:
persistenceEngine = None
def __new__(cls, type_, bases, dict_):
''' cls is the metaclass instance (EntityFactory)?
type_ is the Entity drived class
bases should be 'Entity'
dict_ should be empty'''
instance = object.__new__(cls)
instance.persistenceEngine = persistenceEngine
instance.isDirty = False
instance.isPersisted = False
return instance
def __call__(self, *args, **kwds):
print("Not callable")
return
def newA( id_ ):
a = EntityFactory.__new__(A.__name__, (Entity, ), {})
if id_ == None:
return a
modelObject = persistenceEngine.getRecordForID(id_)
if modelObject == None:
return a
a.modelObject = modelObject
a.isPersisted = True
return a
class Entity(object, metaclass=EntityFactory):
id_ = None
#save and load to legacy file through model here
class A(Entity):
pass