[Grok-dev] Re: Question about viewlets

Martijn Faassen faassen at startifact.com
Thu May 1 17:22:53 EDT 2008

Hi there,

Kevin Smith wrote:
> IOW since grok.viewletmanager and grok.context *cannot* be expressed as 
> a simple attributes, they *must* be grok directives, and
> since grok.order can be expressed as a simple attribute it must not be a 
> grok.directive.
> I mention this since it seems to fit into the recent "what is grok/what 
> is not grok" discussion.

I see 'grok.order' as something that will gain a meaning in other places 
than just viewlets, particularly in menu definitions.

You should see grok.order as related to things like grok.title and 
grok.description (and hopefully one day grok.icon). The idea is a future 
menu generator can make use of this information to deduce what should be 
in there, just like viewlets already do.

Note that grok.order() is a bit more advanced than you might suspect at 
first. The rules for grokcore.component.util.sort_components:

1. if grok.order() is used explicitly with a numeric argument, that will 
be used for sorting. Objects without explicit order will sort before this.

2. if grok.order() is used without an argument, things are ordered in 
definition order. If multiple modules are in play, they'll be sorted by 
dotted module name.

3. if grok.order() is altogether missing, unfortunately some python 
limitations make it impossible to use implicit ordering as in 2. Instead 
  we sort on class name to have at least some consistent ordering.

The idea is that we try to at least define a consistent order even if 
you don't include grok.order(). There's a defaulting rule too.

Note that you can always create your own grok.ViewletManager subclass 
that sorts in a different way by overriding the right method.

Anyway, that's why it's a directive: can be used in (potentially) 
multiple situations, and implements defaulting behavior.

(I wonder incidentally why the grok.order sorting logic moved into 
grokcore.component. Nothing appears to use it there and it's not really 
component-architectury. I do think it could be moved down, but perhaps 
further. Maybe martian would be a reasonable place for this, though 
Martian currently doesn't define directive policy at all, which is an 
argument against doing that)



More information about the Grok-dev mailing list