[Grok-dev] @grok.traverse versus traverse

Christian Theune ct at gocept.com
Thu Oct 19 06:45:55 EDT 2006


Hi,

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:

class House(grok.Model):

	def getEntrance(self, name):
		return ...

	def getWindow(self, name):
		return

	def getLevel(self, level):
		return ...

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.

Christian

-- 
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...
Name: signature.asc
Type: application/pgp-signature
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 mailing list