[Zope-dev] ZPatterns: using PythonMethods from Skinscript

Phillip J. Eby pje@telecommunity.com
Thu, 30 Nov 2000 16:25:43 -0500


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.