[ZPatterns] Rack.getItem returning attributeless objects (ZPatterns newbie)

Phillip Crumpler phillip@crumpler.com.au
Fri, 6 Jul 2001 00:41:44 +1000


Hi folks,

I'm having a few problems with some ZPatterns stuff at the moment and I was
hoping someone out there could help me out with a little Zen magic...

The story so far: I have begun to develop an app based on ZPatterns - it has
quite a few different specialists and a fair chunk of code gluing all of the
bits together, but so far has just been dealing with objects stored within
the Rack. Now that most of the work is done I'm trying to move all of the
storage out to a database using skinscript.

 Things aren;t quite going as they are supposed to so I'm trying to get the
simplest possible scenario working. The setup is Zope-2.3.3, Python 2.1,
Zpatterns-0.4.3p1 on FreeBSD 4-STABLE - I have also tried Python 1.5.2, with
the same results.

 I have a specialist, with the default rack, storing a zclass derived from
DataSkin. The rack is set to 'load by accessing attribute: id'. Within the
specialist are a few sql methods: SQL_get, SQL_change, SQL_create,
SQL_delete. The table has two columns, id (int) and name (text). The zclass
has a simple index_html method to show the instance's id and name
attributes.

The rack has a skinscript method like so:

WITH SQL_get(id=self.id) COMPUTE id, name

WHEN OBJECT ADDED CALL SQL_create(id=self.id, name=self.name)

WHEN OBJECT CHANGED STORE id, name USING SQL_change(id=self.id,
name=self.name)

WHEN OBJECT DELETED CALL SQL_delete(id=self.id)

I'm new to skinscript, so I'm not too sure about this. The only other Data
Plug-In in the rack is a SpecialistPlugIn (but the Specialist itself has no
Data Plug-Ins)

My (first) problem is this: a call to Rack.getItem will _always_ return an
instance - if SQL_get returns no rows then it just ends up with no
attributes. This means I cannot use Specialist.newItem, since:
  Specialist.newItem
  calls Rack.newItem
  calls Rack.createItem
  calls Rack.getItem , to check if the id is already used, then
  calls Rack.retrieveItem , which instantiates a new brainless zclass and
hands it back, which makes createItem choke, because it thinks this id is
already taken.

 I could always just get brutal and insert it into the database directly but
I think that would really be missing the point ;^)  How do I make
Rack.getItem return None in this case?

Specialist.getItem works fine for ids that are in the db.

Natuarally the first person to answer will be dobbing themselves in for a
bunch of other question, like:
- what is the best way to use auto generated ids from the database? Override
the Racks newKey method to get a new value from the db?
- what are Common Instance property sheets and dataskin attribute property
sheets, available to zclasses derived from DataSkin?
- Have SheetProviders been implemented in ZPatterns? How are they used?
- is there any more doco available about this sort of thing? At the moment i
have the wiki (which is excellent) and the SkinScript syntax guide.

but that's a whole 'nother email ;^)


Cheers,

Phillip

ps: I'm subscribed to the digest, so please cc: any responses to me.