-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Martin, thanks a much for your support.

Sorry for my questions, I'm zope/plone newbie, just trying to move out
from Java. Someone advised to try Boring first, so I did. Now I'm trying
to play with ZopeSkel and the 'plone' template.

My src contains now namely:

./oit.jwfind:
docs  oit  oit.jwfind.egg-info  README.txt  setup.cfg  setup.py

./oit.jwfind/oit:
__init__.py  __init__.pyc  jwfind

./oit.jwfind/oit/jwfind:
configure.zcml  CrudExample.pyc  __init__.pyc
CrudExample.py  __init__.py      tests.py

I registered the package in the buildout.cfg:

[buildout]
eggs =
    oit.jwfind
develop =
    src/oit.jwfind

[instance]
zcml =
    oit.jwfind


CrudExample.py contains the whole tentative code, taken from
plone.z3cform docs:

from plone.z3cform.crud import crud
from plone.z3cform.tests import setup_defaults
from plone.z3cform.layout import wrap_form

setup_defaults()

from zope import interface, schema
class IPerson(interface.Interface) :
    name = schema.TextLine()
    age = schema.Int()

class Person(object):
    interface.implements(IPerson)
    def __init__(self, name=None, age=None):
        self.name, self.age = name, age
    def __repr__(self):
        return "<Person with name=%r, age=%r>" % (self.name, self.age)

# names - keys in storage
storage = {'Peter': Person(u'Peter', 16),
           'Martha': Person(u'Martha', 32)}

# form def
class MyForm(crud.CrudForm):
    update_schema = IPerson

    def get_items(self):
        return sorted(storage.items(), key=lambda x: x[1].name)

    def add(self, data):
        person = Person(**data)
        storage[str(person.name)] = person
        return person

    def remove(self, (id, item)):
        del storage[id]

MyView = wrap_form(MyForm)

And I hope I registered the MyView this way in configure.zcml:

<configure
    xmlns="http://namespaces.zope.org/zope";
    xmlns:five="http://namespaces.zope.org/five";
    xmlns:browser="http://namespaces.zope.org/browser";
    i18n_domain="oit.jwfind">

    <include package="oit.jwfind" />

    <browser:page
        for="oit.jwfind.CrudExample.IPerson"
        class="oit.jwfind.CrudExample.MyView"
        name="list_persons"
        permission="cmf.ReviewPortalContent"
    />

</configure>

But now, I'm fumbling what to do next to see any results in Plone.
My final aim is to create a set of forms integrated into Plone site,
which would be able to manipulate objects persisted in RDBMS.

Wishing you a good week

David


Martin Aspeli napsal(a):
> Hi David,
> 
>> I'm playing with a simple product called JWFind, derived from Boring
>> (http://www.zope.org/Members/gtk/Boring) now. The product sits in the
>> products directory, can be added and removed using ZMI, it seems OK.
> 
> Note that Boring is 8.5 years old. I haven't looked at it, but I really
> doubt it follows current best practice. If you want a starting point, I
> suggest you install ZopeSkel and use the 'plone' template.
> 
>> Because I'm willing to use it in Plone, the Zope version is 2.10.6-final.
>>
>> Now, I'm trying to handle the view of product using form made of
>> z3c.form. There is a problem. Currently, I'm getting
>>
>> Traceback (innermost last):
>>   Module ZPublisher.Publish, line 119, in publish
>>   Module ZPublisher.mapply, line 88, in mapply
>>   Module ZPublisher.Publish, line 42, in call_object
>>   Module Products.JWFind.JWFind, line 55, in index_html
>>   Module z3c.form.form, line 189, in __call__
>>   Module z3c.form.form, line 184, in update
>>   Module z3c.form.form, line 134, in update
>>   Module z3c.form.form, line 120, in updateWidgets
>>   Module zope.component._api, line 103, in getMultiAdapter
>>   Module zope.component._api, line 103, in getMultiAdapter
>> ComponentLookupError: ((<Products.JWFind.Person.Person object at
>> 0xb5003b2c>, <HTTPRequest, URL=http://localhost:8091/pokus/index_html>,
>> <JWFind at /pokus>), <InterfaceClass z3c.form.interfaces.IWidgets>, u'')
> 
> It looks like oyu haven't wired up z3c.form properly. You need to use
> plone.z3cform if you're using z3c.form in Plone. Look at its README for
> details.
> 
>> I guess, the error tells, that something implementing ``IWidgets``
>> cannot be found. But, I have no idea, how to deal with it. Maybe, should
>> I prepare the specific layer and skin to be able to use z3cforms and If
>> so, how to do it and especially how to register it properly? Or is there
>> a problem with the form definition itself? Or should I register
>> something to zope in addition to registration made in __init__?
> 
> plone.z3cform takes care of this. The registration is in configure.zcml
> these days. We tend to keep our __init__.py's empty if we can (AT
> content types being the big example).
> 
>> The relevant part of product source JWFind.py:
>>
>>     def index_html(self, REQUEST=None):
>>     """JWFind Form"""
>>     out = Person(self, REQUEST)()
>>     return out.PersonView
> 
> This may work, but it's not really how you're meant to build forms.
> Please look at the plone.z3cform and z3c.form documentation on pypi.
> 
>> The form is in separate file Person.py:
>>
>> from zope import interface, schema
>> from z3c.form import form, field, button
>> from plone.app.z3cform.layout import wrap_form
>>
>> class IPerson(interface.Interface):
>>     age = schema.Int(
>>     title=u"Age",
>>     required=True)
>>
>> class Person(form.Form):
>>      fields = field.Fields(IPerson)
>>      ignoreContext = True # don't use context to get widget data
>>      label = u"Please enter your age"
>>
>>      @button.buttonAndHandler(u'Apply')
>>      def handleApply(self, action):
>>          data, errors = self.extractData()
>>          print data['age'] # ... or do stuff
>>
>> PersonView = wrap_form(Person)
> 
> Ah, I see that you *are* using plone.z3cform. In this case, just make
> sure your PersonView is registered with browser:page and that
> plone.z3cform's ZCML is loaded. You should then be able to access that.
> The index_html() thing is almost certainly wrong.
> 
> Martin
> 
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAknZH1YACgkQ3oCkkciamVHqewCgnlH6o/7Rz4uboYs9ux3KJX6q
qRYAoITsSZbR8+vxnP8Vn51Svu71hu1B
=BPST
-----END PGP SIGNATURE-----

_______________________________________________
Product-Developers mailing list
[email protected]
http://lists.plone.org/mailman/listinfo/product-developers

Reply via email to