hi there

I am having trouble getting form's generated for zope.schema.Object. After doing some more reading it looks like I should be using formlib instead of zope.app.form.browser.add.AddView and zope.app.form.browser.editview.EditView


(my new code will be at the bottom)

Which is fine because I was really having trouble getting zope.schema.Object to work properly. Of course, now I am running into the same basic problem with formlib. It looks like I need to specify some sort of custom widget for my zope.schema.Object. If I don't I get the same ComponentLookupError I was getting with the old system.

I tried the zope.app.form.CustomWidgetFactory, and that actually got that part of the form to show up but it didn't work right. If someone could tell me what I should be doing that would be great.

Also.... one other kinda bizarre thing, in my formlib form all the button text and messages where in German (I think, my German is a little rusty).

An aside... I have been really surprised by the lack of other people having the same problems or working examples else where. I think I'm trying to do something very basic that would come up in lots of applications. This makes me think that I'm going about this the wrong way, or the solution is very simple and I'm just being too dense to get it. So basically, if anyone out there has some commentary on my approach to this problem I would really appreciate it.

thanks.

-jachin

# -=interfaces.py=-

from zope.interface import Interface
from zope.schema import TextLine, Int, Object

class IStreetAddress(Interface):
        """A street address"""
        
        street = TextLine(
                title=u"street",
                description=u"",
                required=False)


class IABookEntry(Interface):
        """An address book entry"""
        streetAddress = Object(
                schema=IStreetAddress,
                title=u"Street Address",
                description=u"",
                required=False)
        
        
        firstName = TextLine(
                title=u"First Name",
                description=u"",
                required=False)
        

# -=entry.py=-

from zope.interface import implements
from zope.formlib import form
from zope.schema.fieldproperty import FieldProperty
from zope.app.form import CustomWidgetFactory
from zope.app.form.browser import ObjectWidget
from persistent import Persistent
from interfaces import IStreetAddress
from interfaces import IABookEntry


class StreetAddress(Persistent):
        """The Street Address object."""
        
        implements(IStreetAddress)



class ABookEntry(Persistent):
        """The Address Book Entry object."""
        implements(IABookEntry)
        streetAddress = StreetAddress
        firstName = u""

class ABookEntryEditView(form.EditForm):
        form_fields = form.Fields(IABookEntry)
        form_fields["streetAddress"].custom_widget =
                                                                                
            ^^^^^^^^^^^^
                                                                                
what should go here?

<!-- -=configure.zcml=- -->

<configure
        xmlns="http://namespaces.zope.org/zope";
        xmlns:browser="http://namespaces.zope.org/browser";>
        
        <content class=".entry.StreetAddress">
                <require
                        permission="zope.View"
                        interface=".interfaces.IStreetAddress"
                        />
                <require
                        permission="zope.ManageContent"
                        set_schema=".interfaces.IStreetAddress"
                        />
        </content>
        
        <content class=".entry.ABookEntry">
                <require
                        permission="zope.View"
                        interface=".interfaces.IABookEntry"
                        />
                <require
                        permission="zope.ManageContent"
                        set_schema=".interfaces.IABookEntry"
                        />
        </content>
        
        <browser:page
                for=".entry.IABookEntry"
                name="index.html"
                template="entry.pt"
                
                class=".entry.ABookEntry"
                permission="zope.Public"
                
                />
        
        <browser:page
                for=".entry.IABookEntry"
                name="edit.html"
                template="edit.pt"
                class=".entry.ABookEntryEditView"
                menu="zmi_views"
                title="Edit"
                permission="zope.ManageContent"
                />
        
        <browser:addMenuItem
                title="ABook Entry"
                class=".entry.ABookEntry"
                permission="zope.ManageContent"
                />
        
</configure>


<!-- -=entry.pt=- -->

<html metal:use-macro="context/@@standard_macros/view">
<body>
<div metal:fill-slot="body" tal:content="view">
</div>
</body>
</html>

<!-- -=edit.pt=- -->

<html metal:use-macro="context/@@standard_macros/view">
<body>
<div metal:fill-slot="body" tal:content="view">
</div>
</body>
</html>



_______________________________________________
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users

Reply via email to