ZPatterns: using PythonMethods from Skinscript
hi out there, this is my first posting on this list. Right now I think this is the right place to ask details about ZPatterns. I think a ZPatterns-Mailinglist should be set up, where people like me, working hard to get the "Zen of ZPatterns" can discuss questions related to USING ZPatterns. Here my first little problem: I've a db_sequence specialist who serves the Framework with db_id's for new Records like:
newid = db_sequence.getItem('<sequence_name>').nextid
The Attribute nextid is provided by a Skinscript-Method: ________________________________________________ WITH getNextId(seq_name=self.id) COMPUTE seq_name=seq_name,nextid=_.int(nextid) ________________________________________________ "getNextId()" is a PythonMethod and uses ZSQL-Methods to compute the NextId while Locking the Table: ________________________________________________ PARAMETER: self, seq_name ________________________________________________ self.sql_Lock() nid = 1 for cur_id in self.sql_NextIdGet(seq_name=seq_name): nid = cur_id.nextid + 1 self.sql_NextIdUpdate(seq_name=seq_name,nextid=nid) break else: self.sql_NextIdCreate(seq_name=seq_name,nextid=1) self.sql_Unlock() return {'seq_name':seq_name, 'nextid':nid} # HERE'S MY PROBLEM I THINK !!!! ________________________________________________ I tried to return nearly everything expect a certain instance of a "special getNextId-Return-Object" e.g. return nid / return (seq_name,nid) ... I tried serveral ways to reach my return values in the SSMethod: ... COMPUTE nextid=nextid or nextid=self.nextid or nextid=RESULT ... Finally i tried to follow what happens during a get-call of an Attribute in the source .. no success .. except when i use some Dummy ZSQL-Method which does the following and works (but this is not the way to do it ..) "select <value> as nextid, <value> as seq_name" can someone give some advice or enlighten me about the Namespace I'm in, at SSMethods Attribute providers at execution-time ?!? My Second "little" Problem: i'm not the first one who had problems to manage data with rdbms and zpatterns. i can get Attributes through SSMethods easily and now tried to setup ADD/CHANGE/DELETED Rules to manage data. Here my SSMethod for this(getEventById/insertEvent/updateEvent are ZSQL-Methods): WITH QUERY getEventById(id=self.id) COMPUTE sid=_.int(id),name,time_start WHEN OBJECT ADDED CALL insertEvent(id=self.sid) WHEN OBJECT ADDED,CHANGED STORE sid,name,time_start USING updateEvent(id=self.sid,name=self.name,time_start=self.time_start) I access the Item through loadAttribute: "sid" I set up a ZClass derived from Dataskin which acts as Storage-Class. I call <dtml-let ni="newItem(key=db.getItem('data_event').nextid)" nips="ni.propertysheets.get('Basic')"> <dtml-var "nips.manage_changeProperties(REQUEST=REQUEST)"> </dtml-let> and get back an empty object without any attributes (propertysheet-problem??) the record in the database is created (but only because I reduced the ZSQL-Insert Method to id-parm only) this again seems to be a Problem of the namespace I'm in while the _objectAdded() ... method. - Do I need a PropertySheet when I only want to access/change/create/delete Items/Attributes from a RDBMS ?? If yes: Which one (CommonInterfaceProp/DataSkinProp) If no: how do i Access/Change my Properties ?? - and another Question related to this: Which object fires the Trigger-Event (ADDED/CHANGED/DELETED) .. is it the PropertySheet itself ??? lots of questions still there but these are the points i really tried to get working .. but i did'nt.. hope that there is an answer .. thanks in advance Ulrich Eck net-labs
At 04:39 PM 11/30/00 +0100, Ulrich Eck wrote:
<excerpt><fontfamily><param>Arial</param><smaller>I've a db_sequence specialist who serves the Framework with db_id's for new Records like: </smaller></fontfamily></excerpt><<<<<<<< May I suggest calling your Specialist "Sequences" or "Counters" since it appears that it returns objects which produce sequential integer values?
<excerpt><fontfamily><param>Arial</param><smaller>>>> newid = db_sequence.getItem('<<sequence_name>').nextid </smaller></fontfamily> <fontfamily><param>Arial</param><smaller>The Attribute nextid is provided by a Skinscript-Method: ________________________________________________ WITH getNextId(seq_name=self.id) COMPUTE seq_name=seq_name,nextid=_.int(nextid) ________________________________________________ </smaller></fontfamily></excerpt><<<<<<<< I would not suggest using nextid as an attribute. This should really be a method, e.g. getNextId(). The method should then return the result of calling Counters.getNextId(seq_name=self.id). However, if you insist on using the above approach, your SkinScript should read: WITH getNextId(seq_name=self.id) COMPUTE nextid=RESULT['nextid'], seq_name=RESULT['seq_name'] Notice that since your Python method returns a dictionary, RESULT is a dictionary, not an object, so you have to retrieve the elements you want in your expressions that way. Of course, you could just have getNextId() return an integer result, and use: WITH getNextId(seq_name=self.id) COMPUTE nextid=RESULT WITH SELF COMPUTE seq_name=id to achieve the same effects.
<excerpt><fontfamily><param>Arial</param><smaller> My Second "little" Problem: i'm not the first one who had problems to manage data with rdbms and zpatterns. i can get Attributes through SSMethods easily and now tried to setup ADD/CHANGE/DELETED Rules to manage data. Here my SSMethod for this(getEventById/insertEvent/updateEvent are ZSQL-Methods): WITH QUERY getEventById(id=self.id) COMPUTE sid=_.int(id),name,time_start WHEN OBJECT ADDED CALL insertEvent(id=self.sid) WHEN OBJECT ADDED,CHANGED STORE sid,name,time_start USING updateEvent(id=self.sid,name=self.name,time_start=self.time_start) </smaller></fontfamily> <fontfamily><param>Arial</param><smaller>I access the Item through loadAttribute: "sid" I set up a ZClass derived from Dataskin which acts as Storage-Class. </smaller></fontfamily> <fontfamily><param>Arial</param><smaller>I call </smaller></fontfamily> <fontfamily><param>Arial</param><smaller><<dtml-let ni="newItem(key=db.getItem('data_event').nextid)" nips="ni.propertysheets.get('Basic')"> <<dtml-var "nips.manage_changeProperties(REQUEST=REQUEST)"> <</dtml-let> and get back an empty object without any attributes (propertysheet-problem??) the record in the database is created (but only because I reduced the ZSQL-Insert Method to id-parm only) this again seems to be a Problem of the namespace I'm in while the _objectAdded() ... method. </smaller></fontfamily></excerpt><<<<<<<< Here's what you're missing. There is no "sid" attribute when you add an object. You need to add this to your SkinScript (assuming I'm guessing correctly what sid is supposed to be): INITIALIZE OBJECT WITH sid=_.int(self.id) Otherwise, your two ADDED triggers will execute with no value for the sid attribute.
<excerpt> <fontfamily><param>Arial</param><smaller>- Do I need a PropertySheet when I only want to access/change/create/delete Items/Attributes from a RDBMS ?? If yes: Which one (CommonInterfaceProp/DataSkinProp) If no: how do i Access/Change my Properties ?? </smaller></fontfamily></excerpt><<<<<<<< Yes. DataSkin Property sheets would be the ones you need to use.
<excerpt> <fontfamily><param>Arial</param><smaller>- and another Question related to this: Which object fires the Trigger-Event (ADDED/CHANGED/DELETED) .. is it the PropertySheet itself ??? </smaller></fontfamily></excerpt><<<<<<<< When you change the attributes of the object, the action is logged for the trigger to fire at transaction commit time. The Property Sheet is just a way to change the attributes.
participants (2)
-
Phillip J. Eby -
Ulrich Eck