Edward Zwart wrote:
> Thanks Simon, I just learned my mistake was I needed to start the
> interactive prompt with bin/myproj-debug.exe. I get the root obj for
> free, and I even get all the buildout eggs in the path this way. Life
> is good!
> However, I have another question now...
> In the z3c.form documentation here:
> In the section on Custom Widget Factories (CTRL + F "MyEditForm")
> Even if I start my interactive prompt with myproj-debug.exe, the following
>>>> myEdit = MyEditForm(root[u'srichter'], TestRequest())
> gives a KeyError (naturally). I am guessing this refers to some
> object representing Stephan's logged in credentials? How is this
The presence of the 'srichter' key in the root folder is not related to
stephan's login, but rather is caused by the code in the "Submitting an
add form successfully" section earlier in that doctest. In that
section, an add form submission is simulated. Before the
"addform.update()" the root folder is empty, but afterward it has the
> I have a feeling that if I get that far, I may have all I need for a
> good while! :)
I've had that feeling too, but it never lasts long :)
> On Tue, Jun 23, 2009 at 1:12 AM, Simon Elbaz<elbazsim...@gmail.com> wrote:
>> the way I've seen to get the root Folder is:
>> from zope.site import folder
>> r_folder = folder.rootFolder()
>> On Tue, Jun 23, 2009 at 9:36 AM, Edward Zwart <ed.zw...@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
>>> from z3c.form import testing, form, field
>>> from z3c.form.testing import TestRequest
>>> request = TestRequest()
>>> 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.
>>> Zope3-users mailing list
> Zope3-users mailing list
Zope3-users mailing list