[Grok-dev] @grok.traverse versus traverse
ct at gocept.com
Thu Oct 19 06:45:55 EDT 2006
Martijn Faassen wrote:
> Hi there,
> I saw that Philipp implemented the @grok.traverse decorator (and the
> grok.Traverse base class), cool!
> I wondered though whether a decorator to mark the traverse is really
> needed. Alternatively we could just have an optional 'traverse' method
> on models. This means that there's no more need to check whether
> traverse is defined multiple times and the like.
> This would follow the same pattern as we did with 'before' on views,
> when we went from decorator to method. I'd suggest as a design rule we
> only use decorators if there's no sane method-based solution.
Sounds reasonable. However, what about this scenario: You have a model
class that defines multiple "getFoo" methods, like:
def getEntrance(self, name):
def getWindow(self, name):
def getLevel(self, level):
With the decorator, I could say @grok.traverse to select one of those
for traversal without rewriting anything. With before I'd have to do an
indirection with code, I don't know how often this pattern would
actually set in, but I'd like to be able to use a decorator in this
case, I think.
gocept gmbh & co. kg - forsterstraße 29 - 06112 halle/saale - germany
www.gocept.com - ct at gocept.com - phone +49 345 122 9889 7 -
fax +49 345 122 9889 1 - zope and plone consulting and development
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 252 bytes
Desc: OpenPGP digital signature
Url : http://mail.zope.org/pipermail/grok-dev/attachments/20061019/f5bb46b5/signature.bin
More information about the Grok-dev