[Zope] ZClass Adding Magic Needed

Geoffrey L. Wright geoff@northernwastes.org
17 Jan 2001 11:52:19 -0900


Jim Washington <jwashin@vt.edu> writes:

> Hi, Geoff
> 
> Your situation looks like application logic confusion enhanced by the
> weirdness of DTML.

Application logic confusion in what way?

Perhaps I didn't give enough detail about what I'm doing.  Here's a
little ASCI art that may clear things up:

  CLASS     META TYPE   PROPERTIES
  ----------------------------------
  ZClass1   (blob)       -> id, displayOrder
     \
      \
      \/
    ZClass2 (chunk)      -> id, displayOrder, alignment, text

ZClass1 is basicly a container class for a bunch of displayable
subobjects.  

Each blob can contain a variable number of chunks, although for the
purpose of creating a new blob I'm only concerned about it starting
with a single chunk.

Right now (if I create a number of sample blobs and chunks by hand)
users can manipulate the display order of individual chunks within a
blob.  The can also manipulate the display order of blobs relative to
one another.

But now I need to give them the capacity to generate a new blob with
one default chunk.  This _seems_ like it should be an easy thing to
do.  And in fact I have no problem with creating a public add method.
My problem comes when I want to give these two new objects starting
values from the same form.  Something like this works perfectly:

<dtml-with "manage_addProduct['ChunkProduct']">
  <dtml-call "chunk_blobClass_add(_.None, _, NoRedir=1)">
</dtml-with>

Where I change the add method of a blob to also always also add a
chunk and appropriately adjust the permession of my add method so that
anybody can use it.

The user will need to control the the displayOrder of the blob.  It's
default chunk will always have a displayOrder of 1.  The user also
needs to control the alignment and text of the default chunk.

And note again that when both the blob and it's chunk are created they
are given a random id based on ZopeTime, since I don't want my users
to have to care about the id of either object.  Because of this I
don't need to worry about passing an id to either one of them from my
form...

I hope this at least manages to clear up my problem a bit.

> Use a Python Script/Method to do the background heavy lifting. If you
> are using <with>, <let>  and REQUEST.set() to access your items, it can
> be done much more simply and understandably in a Python Script/Method.  

I'm open to doing this the Python Way as well, but I have the same
problem there.

> -- Jim Washington
> 
> "Geoffrey L. Wright" wrote:
> > 
> > So:
> > 
> > I have a odd little problem that I can't seem to solve.  I have two
> > zclasses.  We'll call them zclass1 and zclass2.  zclass2 lives inside
> > of zclass1.  zclass1 has the following two properties:  id and
> > displayOrder.  zclass2 has the four properties: id, displayOrder,
> > alignment and content.  In both cases the id is an automaticly
> > generated unique number based on ZopeTime.
> > 
> > My problem is that I need to make a public add method that generates a
> > new instance of zclass1 with a new instance of zclass2 inside of it.
> > I also need to be able to control set the displayOrder of zclass1, and
> > the alignment and content of zclass2 from the same form.  The
> > displayOrder of zclass2 will be static for the time being, but I'll
> > ultimately need to control that as well.
> > 
> > I hacked the default add method of zclass1 so that it generates a new
> > instance of zclass2 each time, and using the Job Board HOWTO I managed
> > to make a public add method.  So far so good.  But now I can't for the
> > life of me figure out how to pass some form variables to one object
> > and some to the other, especially while they have some identically named
> > properties.
> > 
> > Any hints on this one?