Re: [Modeling-users] access of custom object properties
Status: Abandoned
Brought to you by:
sbigaret
From: Sebastien B. <sbi...@us...> - 2003-04-24 16:13:31
|
Hi, Mario Ruggier <ma...@ru...> writes: > hi, >=20 > what does everyone do when wanting to systematically access > all, or a subset of, property values of a custom object to something > else, such as looping to generate html. What is the cleanest and most > efficient way to a) know the list of class property names, and b) to loop > over them to obtain their value (without having to do dirty tricks such as > calculating the get method name for the property, and then eval'ing or > calling that in some way, or accessing directly the instance private > attribute for the property). A very quick answer to your first question, I'll answer the second one later. Short answer: Entity.classProperties(), classPropertiesNames(), classProperties_attributes(), classProperties_relationships() and KeyValueCoding i.e.:=20 >>> from StoreEmployees.Executive import Executive >>> from Modeling import ModelSet >>> ms=3DModelSet.defaultModelSet() >>> # >>> # Howto get class properties (given the model) >>> # >>> executive_entity=3Dms.entityNamed('Executive') >>> [a.name() for a in executive_entity.classProperties()] ['firstName', 'officeLocation', 'lastName', 'marks', 'toAddresses', 'toStor= e'] >>> executive_entity.classPropertiesNames() # alternatively ['firstName', 'officeLocation', 'lastName', 'marks', 'toAddresses', 'toStor= e'] >>> [a.name() for a in ee.classProperties_attributes()] ['firstName', 'officeLocation', 'lastName'] >>> [a.name() for a in ee.classProperties_relationships()] ['marks', 'toAddresses', 'toStore'] >>> # >>> # Howto get a value: use KeyValueCoding! >>> # >>> from Modeling.FetchSpecification import FetchSpecification >>> from Modeling.EditingContext import EditingContext >>> ec=3DEditingContext() >>> fs=3DFetchSpecification('Executive') >>> executives=3Dec.objectsWithFetchSpecification(fs) >>> >>> executives [<StoreEmployees.Employees.Executive instance at 0x863c104>] >>> [[e.valueForKey(k) for k in executive_entity.classPropertiesNames()] fo= r e in executives] [['John', '4XD7', 'Cleese', <Modeling.FaultHandler.AccessArrayFaultHandler = instance at 0x863a53c>, <Modeling.FaultHandler.AccessArrayFaultHandler inst= ance at 0x839b7b4>, <StoreEmployees.Store.Store instance at 0x863b16c>]] Is that what you meant? =20=20 -- S=E9bastien. > Also, is moving to new-style properties foreseen, or are we stuck with > support for 2.1 for a long time? Or, is it possible to support both > new style props, as well as 2.1? >=20 > Regards, mario >=20 >=20 >=20 > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Modeling-users mailing list > Mod...@li... > https://lists.sourceforge.net/lists/listinfo/modeling-users |