[Grok-dev] Manipulating the Grok ZODB via Script.

Uli Fouquet uli at gnufix.de
Mon Jul 19 17:41:47 EDT 2010


Hi there,

jure wrote:

[snip]
> ok, i'm getting some weird KeyError-s, if I try to create a container in 
> the script, which I run with bin/interactive_debugger.
> 
> ...
> root = conn.root()
> myapp = root['myapp']
> myapp['newfolder'] = grok.Container()
> 
> throws KeyError: u'newfolder' .

Please note that this _could_ be triggered by the fact, that there
already exists some object called ``newfolder`` in your `myapp`.
Containers (grok.Applications are also containers) raise a KeyError if
you try to add obejcts under the same name more than once. In that case
you have to delete the old object first:

  >>> del myapp['newfolder']
  >>> myapp['newfolder'] = ...

> I would rather run this setup code in an event handler anyway, so guess 
> I should wait for the new grok release and the 
> grok.IApplicationInitializedEvent ?

This event was already available with Grok 1.1. Only grokui.admin did
not trigger it when creating applications, which was fixed with
grokui.admin 0.7.0 thanks to Souheil.

>  Creating new objects in the 
> ObjectAdded or ObjectCreated event handler for the app probably isn't 
> the best idea. The ObjectAddedEvent is fired when I add the objects to a 
> container, but something else goes wrong along the way, because they 
> don't get an IntId..
> Is it possible to use the new grok.admin without breaking something else?

If you're using a fairly recent Grok version that shouldn't be a
problem. I _think_ at least Grok >= 1.1 should be sufficient. I might be
wrong here, though.

Best regards,

-- 
Uli

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://mail.zope.org/pipermail/grok-dev/attachments/20100719/71bd4884/attachment.bin 


More information about the Grok-dev mailing list