[Grok-dev] getSite returning None...

Jeroen Michiel jmichiel at yahoo.com
Tue Mar 9 02:44:25 EST 2010


I found it!

I was doing this in my code:

try: 
    from zope.site.hooks import getSite
except ImportError:
    # BBB stay compatible with Grok 1.0 
    from zope.app.component.hooks import getSite

So, for Grok 1.0, you end up in the except clause, but for some reason this
messes up the siteinfo object that is created in the hooks module (or it is
created twice, and the publisher works with the other one, while my menus
keep referring to this one). In any case something quite weird!

I changed it to

try: 
    from zope.site.hooks  import getSite
except ImportError:
    pass 

try: 
    # BBB stay compatible with Grok 1.0 
    from zope.app.component.hooks  import getSite
except ImportError:
    pass 

and it works now.
I don't know if there's a more elegant solution?


Souheil CHELFOUH wrote:
> 
> The site is set upon traversal. It's maybe a problem in that operation.
> Have you tried to hook up a pdb in your property to see what's happening ?
> Do you have a test in your property to see what it returns ?
> Can you give us more info
> 
> 2010/3/5 Jeroen Michiel <jmichiel at yahoo.com>:
>>
>> Hi,
>> I'm having a strange problem im megrok.navigation.
>> For site menuitems (linking to a view of the closest site object), I use
>> the
>> getSite function from zope.app.component.hooks (for Grok 1.0) in a
>> property
>> method which gets called when the template is rendered.
>> However, it seems that in my current configuration, getSite returns None
>> at
>> that time, while it works perfectly in another project (using Grok1.1a1,
>> however).
>> What could be the reason, or is it just unsafe to use the getSite
>> function
>> for that purpose, and should I do that diferently?
>>
>> thx
>> --
>> View this message in context:
>> http://old.nabble.com/getSite-returning-None...-tp27792398p27792398.html
>> Sent from the Grok mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> Grok-dev mailing list
>> Grok-dev at zope.org
>> https://mail.zope.org/mailman/listinfo/grok-dev
>>
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> https://mail.zope.org/mailman/listinfo/grok-dev
> 
> 

-- 
View this message in context: http://old.nabble.com/getSite-returning-None...-tp27792398p27832363.html
Sent from the Grok mailing list archive at Nabble.com.



More information about the Grok-dev mailing list