Adding and setting properties from a virtual Specialist
Hi, I have a Specialist ('OrderingEntities') which creates virtual objects, mapped to existing objects (using ZClass 'Employee') in another Specialist ('Employees'). I want OrderingEntities to add and modify a property 'current_order_id' on the Employee objects. I can get the virtual object to access properties from the real object, but I can't figure out how to implement the property add/change. To make things simpler, I added the property current_order_id to the Employee class, so I can test just modifying this property, leaving creating it for later. OrderingEntities has an employeeRack, set to use the Employee class and to load by accessing attribute current_order_id. The Rack has this SkinScript: WITH Employees.getItem(self.id) COMPUTE original_object=RESULT or NOT_FOUND WITH self.original_object COMPUTE current_order_id WHEN OBJECT ADDED,CHANGED STORE current_order_id USING self.original_object.manage_changeProperties(current_order_id=self.current_order_id) Doing <dtml-var "OrderingEntities.getItem(some_id).current_order_id)"> shows me the value of current_order_id of the Employee object some_id. But I can't figure out how to change the property so it get changed in the Employee object. <dtml-call "OrderingEntities.getItem(some_id).manage_changeProperties(current_order_id='123')"> does nothing, it doesn't even trigger the WHEN OBJECT CHANGED line (not that I really expected it to work... this object is virtual, how can I call changeProperties on it?) Other than figuring out how to get the change to work, I two more problems: -Eventually the OrderingEntities Specialist will have several Racks mapping to several other Specialists, so it will end up returning different classes. Should I instead create a new ZClass with just the current_order_id property and use this class in all the virtual Racks? - How do I add a property to the original object from the virtual object (assuming I did not add it manually to the Employee class)? Do I call self.original_object.manage_addProperty(...) from the SkinScript? TIA -- Itai Tavor "Je sautille, donc je suis." C3Works itai@c3works.com - Kermit the Frog "If you haven't got your health, you haven't got anything"
Hi Itai,
"Itai" == Itai Tavor <itai@optusnet.com.au> writes:
Itai> "OrderingEntities.getItem(some_id).current_order_id)"> shows Itai> me the value of current_order_id of the Employee object Itai> some_id. But I can't figure out how to change the property Itai> so it get changed in the Employee object. <dtml-call Itai> "OrderingEntities.getItem(some_id).manage_changeProperties(current_order_id='123')"> Itai> does nothing, it doesn't even trigger the WHEN OBJECT Itai> CHANGED line (not that I really expected it to work... this Itai> object is virtual, how can I call changeProperties on it?) How about 'OrderingEntities.getItem(some_id).propertysheets.TheRightPropertysheet.manage_changeProperties(....) or you could create an external method to set the property you want... YourExternalMethod( OrderingEntities.getItem(some_id), theValue) where def YourExternalMethod( theObject, theValue): setattr(theObject, 'current_order_id', theValue) I think these could/should work... Itai> Other than figuring out how to get the change to work, I two Itai> more problems: Itai> -Eventually the OrderingEntities Specialist will have Itai> several Racks mapping to several other Specialists, so it Itai> will end up returning different classes. Should I instead Itai> create a new ZClass with just the current_order_id property Itai> and use this class in all the virtual Racks? This is what I do in most cases... each rack has different SkinScript to map the attributes of different classes onto the common attribute set of the single Storage class used by all the racks. Itai> - How do I add a property to the original object from the Itai> virtual object (assuming I did not add it manually to the Itai> Employee class)? Do I call Itai> self.original_object.manage_addProperty(...) from the Itai> SkinScript? I think this should work.... but it will only add the propertysheet to the instance.. not the class. If the property is completely missing from the original class then it seems to me either there is really no real need to save it there... or the class was incomplete somehow to begin with... and it should be added at the ZClass level.. Just random thoughts... ;-) -steve Itai> TIA -- Itai Tavor "Je sautille, donc je suis." C3Works Itai> itai@c3works.com - Kermit the Frog Itai> "If you haven't got your health, you haven't got anything" Itai> _______________________________________________ Zope-Dev Itai> maillist - Zope-Dev@zope.org Itai> http://lists.zope.org/mailman/listinfo/zope-dev ** No cross Itai> posts or HTML encoding! ** (Related lists - Itai> http://lists.zope.org/mailman/listinfo/zope-announce Itai> http://lists.zope.org/mailman/listinfo/zope )
Steve Spicklemire wrote:
Hi Itai,
"Itai" == Itai Tavor <itai@optusnet.com.au> writes:
Itai> "OrderingEntities.getItem(some_id).current_order_id)"> shows Itai> me the value of current_order_id of the Employee object Itai> some_id. But I can't figure out how to change the property Itai> so it get changed in the Employee object. <dtml-call Itai> "OrderingEntities.getItem(some_id).manage_changeProperties(current_order_id='123')"> Itai> does nothing, it doesn't even trigger the WHEN OBJECT Itai> CHANGED line (not that I really expected it to work... this Itai> object is virtual, how can I call changeProperties on it?)
How about 'OrderingEntities.getItem(some_id).propertysheets.TheRightPropertysheet.manage_changeProperties(....)
Grrrrr.... now I'm really annoyed. Why didn't I try that? So obvious. Thanks.
Itai> Other than figuring out how to get the change to work, I two Itai> more problems:
Itai> -Eventually the OrderingEntities Specialist will have Itai> several Racks mapping to several other Specialists, so it Itai> will end up returning different classes. Should I instead Itai> create a new ZClass with just the current_order_id property Itai> and use this class in all the virtual Racks?
This is what I do in most cases... each rack has different SkinScript to map the attributes of different classes onto the common attribute set of the single Storage class used by all the racks.
Sounds like a good plan, think I'll adopt it.
Itai> - How do I add a property to the original object from the Itai> virtual object (assuming I did not add it manually to the Itai> Employee class)? Do I call Itai> self.original_object.manage_addProperty(...) from the Itai> SkinScript?
I think this should work.... but it will only add the propertysheet to the instance.. not the class. If the property is completely missing from the original class then it seems to me either there is really no real need to save it there... or the class was incomplete somehow to begin with... and it should be added at the ZClass level..
Say I got several Participants, and some of those need to be able to place orders. I create the Specialist OrderingEntities to implement the role of 'someone who places orders'. From what I understand about using Specialists to extend a class behavior, this Specialist should add the properties it needs to track orders with to the Participant classes - I should not have to go in to every Participant class and add the property to it, because those classes don't know and don't care that they might be used in this role. Am I wrong in this? Otherwise, the only other way to track properties for this role would be to physically store a new object on the OrderingEntities Rack for every Participant class accessed, but what's the point in that, if I can simply add the property to the original class? Making small steps up the ZPatterns mountain (and too many of them backwards), Itai -- Itai Tavor "Je sautille, donc je suis." C3Works itai@c3works.com - Kermit the Frog "If you haven't got your health, you haven't got anything"
Hi Itai,
"Itai" == Itai Tavor <itai@optusnet.com.au> writes:
Itai> Say I got several Participants, and some of those need to be Itai> able to place orders. I create the Specialist Itai> OrderingEntities to implement the role of 'someone who Itai> places orders'. From what I understand about using Itai> Specialists to extend a class behavior, this Specialist Itai> should add the properties it needs to track orders with to Itai> the Participant classes - I should not have to go in to Itai> every Participant class and add the property to it, because Itai> those classes don't know and don't care that they might be Itai> used in this role. Am I wrong in this? Otherwise, the only Itai> other way to track properties for this role would be to Itai> physically store a new object on the OrderingEntities Rack Itai> for every Participant class accessed, but what's the point Itai> in that, if I can simply add the property to the original Itai> class? No.. you're right here. I've never used property sheets in this way, just because it's seemed too much trouble to check for existence, then add if necessary... etc. If I need to have a property set in an instance... I just set it, using an external method. (Or I add it at the ZClass level.) It's important to be careful though... if there is already a property with that name.... there could be a clash. Obviously application integration needs to be done with full awareness of the different attributes used by each component. Itai> Making small steps up the ZPatterns mountain (and too many Itai> of them backwards), Yup.. me too. ;-) But it's better than sticks and bones.. take care, -steve Itai> Itai -- Itai Tavor "Je sautille, donc je suis." C3Works Itai> itai@c3works.com - Kermit the Frog Itai> "If you haven't got your health, you haven't got anything"
participants (2)
-
Itai Tavor -
Steve Spicklemire