[Zope] Re: Automatically adding properties (keywords) to folders

2006-04-20 Thread Tres Seaver
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Terry Jones wrote:
> Hi Tres
> 
> Thanks for your answer. Could I trouble you a little bit more please?
> 
> I don't know where I'd put these fragments (and the last one seems
> incomplete, perhaps intentionally?). I'm happy to read and code myself, so
> I don't mean to ask for much here, but I'm not sure what to do with your
> suggestion. I read version 2.6 of the zope book, and today found out
> there's a proto-version 2.7, which I'll take a look at.

Note that the "new way" stuff is only for Zope *later* than 2.8.x.
In that case, you would define the function in a module somewhere on
your $PYTHONPATH (e.g., in $INSTANCE_HOME/lib/python, or in a product)
and then register it in a ZCML file which is included from your
'site.zcml' (in $INSTANCE_HOME/etc).

> Anyway, thanks again.
> 
> Terry
> 
> | The old way to do that we be to derive your own folder class and
> | override '_setObject' / '_delObject' to add your semantics.
> | 
> | The new way (for Zope >= 2.9) would be to register a subscriber for the
> | "container" events which are published automatically.  Something like
> | (untested)::
> | 
> |   def update_keywords(event):
> |   keyword = getattr(event.newparent, 'keyword', None)
> |   event.object.keyword = None
> |   event.object.reindexObject()
> | 
> | and then in ZCML::
> | 
> || for="zope.app.event.objectevent.ObjectEvent"
> | factory="Products.yourproduct.events.update_keywords"



Tres.
- --
===
Tres Seaver  +1 202-558-7113  [EMAIL PROTECTED]
Palladion Software   "Excellence by Design"http://palladion.com
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFER/Iq+gerLs4ltQ4RAvSAAJ9edkh96NO63lrKF6mkuDeAGYSYWQCgp98g
hp/tu+8LtZFYjJvX3rSxuao=
=m3sh
-END PGP SIGNATURE-

-- 
===
Tres Seaver  +1 202-558-7113  [EMAIL PROTECTED]
Palladion Software   "Excellence by Design"http://palladion.com

___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


[Zope] Re: Automatically adding properties (keywords) to folders

2006-04-20 Thread Tres Seaver
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Terry Jones wrote:
> I'd like to set up a folder in Zope with the property that when an object
> is put into it, the object has a keyword added to it automatically (and
> when the object is moved out of the folder, the keyword is removed).
> 
> If you could do this, you would have a nice way to maintain a collection of
> such folders and have their contents appear elsewhere in a collection of
> Plone Smart Folders (using keyword criteria).
> 
> Can anyone tell me how I should best go about doing this?
> 
> I can imagine writing some python to run once in a while, find all the
> contents of the folder, add the keywords, etc. But that's far from being an
> ideal solution.
> 
> Any pointers would be much appreciated.

The old way to do that we be to derive your own folder class and
override '_setObject' / '_delObject' to add your semantics.

The new way (for Zope >= 2.9) would be to register a subscriber for the
"container" events which are published automatically.  Something like
(untested)::

  def update_keywords(event):
  keyword = getattr(event.newparent, 'keyword', None)
  event.object.keyword = None
  event.object.reindexObject()

and then in ZCML::

  http://palladion.com
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFER7/g+gerLs4ltQ4RAjcHAJ9WqoFcbrNIC9h3M5jYEZ8Bmq2jMQCeMjSh
7zE2AI2+rNc39s3bhOMsb4E=
=yYJw
-END PGP SIGNATURE-

___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )