[Zope-dev] How is 'retrieveItem intended to work with TTW Specialists?
Steve Spicklemire
steve@spvi.com
Mon, 25 Sep 2000 08:00:21 -0500 (EST)
Hello ZPatterns Folk.....
I'm trying to implement 'delagation' with a custom Specialist. The idea,
(I think this is one of the goals of ZPatterns... to allow delegation
of responsibility after the Framework is built...)
I have:
a) MarketItemManager (Python subclass of Specialist) Some of methods, both DTML Methods,
and plain old Python Methods, are *meant* to be acquire by the objects (DataSkins)
he manages.
b) ThingManager (ZClass subclass of Specialist). This is really just a test
class that is supposed to represent some later developer integrating
my ZPattern based EMarket into their application, (e.g., inventory or
whatever...)
in MarketItemManager I've defined a 'retrieveItem' (this would really be
done by the integrator...) that does something like this:
<dtml-return "myGreatSite.ThingSpecialist.getItem(key)">
with the hope that when the Specialist class gets traversed
it will execute:
def __bobo_traverse__(self, REQUEST, name):
ob = getattr(self, name, _marker)
if ob is _marker:
ob = self.getItem(name) <--- traversal invokes getItem....
if ob is not None:
return ob
raise 'NotFound'
return ob
def getItem(self, key):
"""Get an item"""
if hasattr(self.aq_base,'retrieveItem'): <--- getItem invokes retrieveItem
return self.retrieveItem(key=key) # XXX need DTML check?
for rack in self.rackList:
item = rack.__of__(self).getItem(key)
if item is not None: return item
So my retrieve item gets called..... *unfortunately* it gets
called without any namespace parameter... so my retrieveItem
DTML method has no way to acquire a namespace so that it can
delagate to something else!
So... here is what I did... I defined a method in my Python
subclass of Specialist..
class MarketItemManager(ZPatterns.Specialists.Specialist):
"""A Market Item Manager"""
# Specify a name for the item type:
meta_type='MarketItemManager'
def retrieveItem(self, key):
""" get an item...."""
return self.__of__(self).delegateRetrieve(self, None, key=key)
Then I made a DTML method called 'delegateRetrieve' like so:
<dtml-return "myGreatSite.ThingManager.getItem(key)">
this way, my integrator can edit 'delegateRetrieve' to point
to whatever Specialist he wants to... and I have a Python
implementation of retrieveItem.
Does this sound OK? Am I working way too hard here?
(I feel like I am! ;-> )
thanks,
-steve