<div class="Ih2E3d">Sorry Martjin, i've forgot to click on reply all:<br><br>"If you create a view like this for your application:<br>
<br>
class Index(grok.View):<br>
def render(self):<br>
intids = component.getUtility(IIntIds)<br>
print intids<br>
return "the result"<br>
<br>
do you still get a component lookup error when you access the view, or<br>
do you get the intids? (assuming you re-installed your app first)."<br><br></div>I'm tried to do this in View (I've inherited from Form, but i guess there is no problem) class indeed.<br><br>I
can only access these utilities (intids and relationCatalog) from the
Application class context. When i try to do "intids =
component.getUtility(IIntIds)" from a diferent context, like: MyApp
->ContainerA --> ContainerB -> Model -> View class a
LookupError is returned. I guess that these utilities should be
accessible in any context, right?<div class="Ih2E3d"><br>
<br>"To make it work in your tests, you might need to do something like this<br>
before you do any getUtility lookups:<br>
<br>
from zope.app.component.hooks import setSite<br>
<br>
setSite(your_app)"<br><br></div>I didn't did this in this test, and the test passed:<br><a href="http://pastebin.com/m10b71a8" target="_blank">http://pastebin.com/m10b71a8</a><br><br>As you see, if i pass the app as context, the getUtility Works. <br>
<br><div class="gmail_quote">2009/2/20 Martijn Faassen <span dir="ltr"><<a href="mailto:faassen@startifact.com">faassen@startifact.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi there,<br>
<br>
Using local_utility should indeed be the right way to set up utilities<br>
with Grok.<br>
<div class="Ih2E3d"><br>
Vanderson Mota dos Santos wrote:<br>
> the problem is, when i try to use component.getUtility(IIntIds), a<br>
> componentLookUpError appear to me.<br>
<br>
</div>...<br>
<div class="Ih2E3d"><br>
> I know this, but the tests are failing. And i'm running them with the<br>
> functional layer. Every time i run the tests, a new instance is<br>
> created(obviously), so, the local_utilities should be accessible.<br>
<br>
</div>It'd be interested to see your failing tests.<br>
<br>
If you create a view like this for your application:<br>
<br>
class Index(grok.View):<br>
def render(self):<br>
intids = component.getUtility(IIntIds)<br>
print intids<br>
return "the result"<br>
<br>
do you still get a component lookup error when you access the view, or<br>
do you get the intids? (assuming you re-installed your app first).<br>
<br>
One thing to know is that in order to lookup local utilities, the<br>
correct site needs to be set first to your application. The normal<br>
traversal process does this for you, which is why I hope that the above<br>
view will do the right thing for you.<br>
<br>
In tests, setSite() may very well not have been used and therefore you<br>
would look up only global utilities, not those for your application object.<br>
<br>
To make it work in your tests, you might need to do something like this<br>
before you do any getUtility lookups:<br>
<br>
from zope.app.component.hooks import setSite<br>
<br>
setSite(your_app)<br>
<br>
Hopefully this will help resolve the problem. If not there might be<br>
something deeper going on...<br>
<br>
Regards,<br>
<font color="#888888"><br>
Martijn<br>
</font><div><div></div><div class="Wj3C7c"><br>
<br>
_______________________________________________<br>
Grok-dev mailing list<br>
<a href="mailto:Grok-dev@zope.org">Grok-dev@zope.org</a><br>
<a href="http://mail.zope.org/mailman/listinfo/grok-dev" target="_blank">http://mail.zope.org/mailman/listinfo/grok-dev</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Vanderson Mota dos Santos<br><br>