Re: [Zope-dev] Image Archive Project (phase 2)

2001-04-10 Thread Michael R. Bernstein

"Michael R. Bernstein" wrote:
 
 Ok, so what's next? Somehow, ArchiveImages must be made
 aware of what Renderings they have.
 
 The ArchiveImage Specialist needs a getRenderingIds() Python
 Script, which in turn calls
 container.Renderings.getRenderingIdsFor().
 
 Now I'm stuck. How do I select all the Renderings that have
 (for example) '001' in their id, and return just the second
 portion of the id (such as 'original' or 'thumbnail')? What
 do I need to put into the getRenderingIds and
 getRenderingIdsFor Python Scripts?

After some head scratching and some advice, I decided to use
a ZCatalog in the Renderings Specialist.

First I added a SkinScript with the following body:

WHEN OBJECT ADDED CALL
Catalog.catalog_object(self,
_.string.join(self.getPhysicalPath(),'/'))
WHEN OBJECT DELETED CALL
Catalog.uncatalog_object(_.string.join(self.getPhysicalPath(),'/'))
WHEN OBJECT CHANGED CALL
Catalog.uncatalog_object(_.string.join(self.getPhysicalPath(),'/')),
Catalog.catalog_object(self,
_.string.join(self.getPhysicalPath(),'/'))
WITH SELF COMPUTE
  external_id  = _.string.split(id,'_')[1],
  associated_image = _.string.split(id,'_')[0]

This ensures hat the objects will be catalogued when they
need to be, as well as establishing two computed attributes,
'external_id' and 'associated_image'.

I added both properties to the ZCatalog as FieldIndexes, and
removed all of the existing indexes except for id.

I also added 'external_id' as a meta-data field.

Now the Renderings.getRenderingIdsFor Python Script takes an
associated_image_id as a parameter, and reads as follows:

 list = []
 list =
container.Catalog({'associated_image':associated_image_id})
 list2= []
 for x in list:
 list2.append(x.external_id)

 return list2

And the main ArchiveImages Specialist has a getRenderingIds
Python Script:

 archive_image_id = context.id

 list =
container.Renderings.getRenderingIdsFor(archive_image_id)
 return list

Finally, I added the following to the index_html for the
ArchiveImages:

dtml-in getRenderingIds
 a href="dtml-var sequence-item"dtml-var
sequence-item/a
/dtml-in

So ArchiveImages now display links to their associated
Renderings.

Any comments or suggestions for improvements gladly
accepted.

Michael Bernstein.

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



[Zope-dev] Image Archive Project (phase 2)

2001-04-09 Thread Michael R. Bernstein

Ok, I now have the following setup:

ArchiveImages (Specialist)
 defaultRack
  traversal (SkinScript)
 traversal_method (Python Script)
 Renderings (Specialist)
  defaultRack

The SkinScript in ArchiveImages/defaultRack simply points
__bobo_traverse__ to traversal_method.

traversal_method, in turn, checks to see if it is being
called with one of a short list of known methods of the
ArchiveImage ZClass, otherwise it returns an object in the
Renderings Specialist.

Which object, you ask? The objects in Renderings are
instances of RackImage (a class that subclasses Image and
DataSkin). Currently, I have hardwired behaviour that
instantiates a RackImage in Renderings when you create an
ArchiveImage. Assuming that the ArchiveImage is created with
an id of '001', then the RackImage is created with an id of
'001_original'.

So when the traversal_method is presented with a path of
'/ArchiveImage/001/original' it returns the object from
'/ArchiveImage/Renderings/001_original'. Thus the
ArchiveImage ZClass appears to have an 'original' attribute
that returns an image.

Here is the traversal_method Python Script:

 import string

 if name in ['index_html', 'editInstanceForm',
'editInstance']:
 return getattr(context, name)
 else:
 rendering = string.join([context.id, name],'_')
 return container.Renderings.getItem(rendering)


Ok, so what's next? Somehow, ArchiveImages must be made
aware of what Renderings they have.

The ArchiveImage Specialist needs a getRenderingIds() Python
Script, which in turn calls
container.Renderings.getRenderingIdsFor().

Now I'm stuck. How do I select all the Renderings that have
(for example) '001' in their id, and return just the second
portion of the id (such as 'original' or 'thumbnail')? What
do I need to put into the getRenderingIds and
getRenderingIdsFor Python Scripts?

TIA,

Michael Bernstein.

P.S. The (currently hardwired) Renderings instantiation code
will be delegated later to another Specialist,
RenderingDisplays.

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )