Re: [Zope3-Users] logging in in interactive shell?

2009-06-23 Thread John

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:
> http://pypi.python.org/pypi/z3c.form/1.9.0
>
> In the section on Custom Widget Factories (CTRL + F "MyEditForm")
>
> Even if I start my interactive prompt with myproj-debug.exe, the following 
> line
>
>   
 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
> achieved?
>   
Hi Edward,

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 
'srichter' key.

> 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 :)

John
> e.
>
> On Tue, Jun 23, 2009 at 1:12 AM, Simon Elbaz wrote:
>   
>> 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  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@zope.org
>>> http://mail.zope.org/mailman/listinfo/zope3-users
>>>   
>> 
> ___
> Zope3-users mailing list
> Zope3-users@zope.org
> http://mail.zope.org/mailman/listinfo/zope3-users
>   
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] logging in in interactive shell?

2009-06-23 Thread Edward Zwart
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:
http://pypi.python.org/pypi/z3c.form/1.9.0

In the section on Custom Widget Factories (CTRL + F "MyEditForm")

Even if I start my interactive prompt with myproj-debug.exe, the following line

>>> 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
achieved?

I have a feeling that if I get that far, I may have all I need for a
good while!  :)

e.

On Tue, Jun 23, 2009 at 1:12 AM, Simon Elbaz wrote:
> 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  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@zope.org
>> http://mail.zope.org/mailman/listinfo/zope3-users
>
>
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] logging in in interactive shell?

2009-06-23 Thread Simon Elbaz
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  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@zope.org
> http://mail.zope.org/mailman/listinfo/zope3-users
>
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users