[Grok-dev] Question about initialing grok.GlobalUtility with data from application containers
Martijn Faassen
faassen at startifact.com
Mon Sep 15 08:09:43 EDT 2008
rmoskal wrote:
> The only way I can think to get this done is to actually pass the
> articles/placements context to the method where I test the validity of a
> placement. I can set a flag to indicate if the GlobalUtility has been
> intialized, and load up the existing data exactly once. This seems
> unsatisfying. Can anyone suggest a more elegant way?
>
> It seems like a common use case.
I'm still trying to understand the use case. Could you perhaps give an
example of a business rule you want to enforce?
I'm just going to list random ideas that come to mind in the hopes that
one works as an answer to you question:
* you can do grok.getSite() within the global utility code to get the
site object; you might be able to traverse to your content that way,
say: grok.getSite()['placements'] to get to your placements container.
* you could catalog your content objects and do a query in the global
utility.
* you could instead of a global utility perhaps get away with doing this
in an IObjectAddedEvent handler.
* it is, I believe, also possible to register a placements containerr as
a local utility directly, though this will need to be done through the
API - I don't think Grok will help much here. You could then define the
business rules on the placements container and just look it up using
component.getUtility()
Regards,
Martijn
More information about the Grok-dev
mailing list