extending objectValues() and objectIds() or ?
I have developed a flock of Python products that have attributes 'first_date', 'last_date', and 'ok_to_publish' with the intention that these attributes will be set by the content managers. Each product also has an 'isPublishable' method that returns true if 'ok_to_publish' is true _and_ today >= 'first_date' _and_ today <= 'last_date'. This all works fine but I find myself writing DTML in many places to retrieve a list of objects with objectValues() and then looping over them making yet another list of only the objects that are publishable. What I would really like is an objectValues() and an objectIds() that return only publishable objects/ids. It looks like this could be easily accomplished by {tremble} adding an additional parameter to those two routines, say chkPub=None so that I could do a call such as objectValues('Poll',1) when I wanted just the publishable Poll items returned. However... 1. modifying ObjectManager.py doesn't seem like the best move I've ever thought of 2. I'm confused about the ObjectManager internals - can I call my isPublishable methods on objects that ObjectManager keeps in its lists? How? I guess a better question, rather than asking about this one possible solution, would be: How can I extend Zope to give me a list of objects qualified by more than just the meta_type? Guidance gleefully gathered. Thanks! -- Dennis Nichols nichols@tradingconnections.com
Write a Python Method (install the PythonMethods product first) called say, publishableObjectValues that does that: <param>self</param> # functions that returns publishable objects result = [] for o in self.objectValues(): if o.isPublishable(): result.append(o) return result -- Itamar S.T. itamar@maxnm.com Fingerprint = D365 7BE8 B81E 2B18 6534 025E D0E7 92DB E441 411C
Thanks for the advice (below). I added another parameter for meta type and everything works great. What's the advantage of using Python Method rather than an external method, other than thru-the-web editing? Any disadvantages? At 10/24/00 06:45 PM, Itamar Shtull-Trauring wrote:
Write a Python Method (install the PythonMethods product first) called say, publishableObjectValues that does that:
<param>self</param>
# functions that returns publishable objects result = [] for o in self.objectValues(): if o.isPublishable(): result.append(o) return result
-- Dennis Nichols nichols@tradingconnections.com
participants (2)
-
Dennis Nichols -
Itamar Shtull-Trauring