[Zope3-Users] logging in in interactive shell?

Simon Elbaz elbazsimon9 at gmail.com
Tue Jun 23 04:12:58 EDT 2009


Hi,
the way I've seen to get the root Folder is:

from zope.site import folder
r_folder = folder.rootFolder()

Regards
Simon


On Tue, Jun 23, 2009 at 9:36 AM, Edward Zwart <ed.zwart at softserv.ca> wrote:

> Is there an easy way to use the interactive shell as though I were the
> logged in admin user?
>
> Following the documentation for z3c.form on Custom Widgets, I try the
> following:
>
> from z3c.form import testing, form, field
> testing.setupFormDefaults()
> from z3c.form.testing import TestRequest
> request = TestRequest()
> testing.setUp(request)
>
> from z3c.form.browser import text
>
> class MyWidget(text.TextWidget):
>        """My new widget."""
>        klass = u'MyCSS'
>
> def MyFieldWidget(field, request):
>        """IFieldWidget factory for MyWidget."""
>        return widget.FieldWidget(field, MyWidget(request))
>
> class MyEditForm(form.EditForm):
>
>        fields = field.Fields(IPerson)
>        fields['name'].widgetFactory = MyFieldWidget
>
>
> myEdit = MyEditForm(root[u'srichter'], TestRequest())
>
> I get "root" is not defined.  So I figured out something like this...
>
> root = request.globs.get('root')
>
> If I try again, I get a KeyError (also if I use "admin").  In fact,
> the root Folder object doesn't have anything in it at all.  (If I log
> in through the ZMI, I have added some objects.)
>
> Is there a more correct way to get the root folder?  And to run these
> tests from the prompt, can I do so as though I was logged in (like I
> do through the ZMI)?
>
> Somewhat related, everytime I use the interactive prompt, I copy/paste
> from bin/test-script.py to set the path to include all my buildout
> eggs folders.  Is there a better way to do this?
>
> Thanks again.
>
> e.
> _______________________________________________
> Zope3-users mailing list
> Zope3-users at zope.org
> http://mail.zope.org/mailman/listinfo/zope3-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/zope3-users/attachments/20090623/ec4c328c/attachment.html 


More information about the Zope3-users mailing list