I add a Limoservice object, then inside that object add a Car; then I add a Driver (which contains a Car), and the AddForm offers a dropdown with '(no value)' and my Car object. If I select the car from the dropdown I get an error:

UnpickleableError: Cannot pickle <type 'zope.security._proxy._Proxy'> objects

Whereas if I leave the dropdown at '(no value)', the error does not occur. What am I doing wrong? (See attached error.txt for full error.)

Thanks yet again!
2008-01-15T06:47:39 ERROR SiteError 
http://localhost:2020/mylimo/+/limoService.Driver%3D
Traceback (most recent call last):
  File "C:\Python24\Lib\site-packages\zope\publisher\publish.py", line 138, in 
publish
    publication.afterCall(request, obj)
  File "C:\Python24\Lib\site-packages\zope\app\publication\browser.py", line 
78, in afterCall
    super(BrowserPublication, self).afterCall(request, ob)
  File "C:\Python24\Lib\site-packages\zope\app\publication\zopepublication.py", 
line 167, in afterCall
    txn.commit()
  File "C:\Python24\Lib\site-packages\transaction\_transaction.py", line 395, 
in commit
    self._commitResources()
  File "C:\Python24\Lib\site-packages\transaction\_transaction.py", line 495, 
in _commitResources
    rm.commit(self)
  File "C:\Python24\Lib\site-packages\ZODB\Connection.py", line 498, in commit
    self._commit(transaction)
  File "C:\Python24\Lib\site-packages\ZODB\Connection.py", line 543, in _commit
    self._store_objects(ObjectWriter(obj), transaction)
  File "C:\Python24\Lib\site-packages\ZODB\Connection.py", line 570, in 
_store_objects
    p = writer.serialize(obj)  # This calls __getstate__ of obj
  File "C:\Python24\Lib\site-packages\ZODB\serialize.py", line 407, in serialize
    return self._dump(meta, obj.__getstate__())
  File "C:\Python24\Lib\site-packages\ZODB\serialize.py", line 416, in _dump
    self._p.dump(state)
UnpickleableError: Cannot pickle <type 'zope.security._proxy._Proxy'> objects
127.0.0.1 - - [15/Jan/2008:06:47:39 -0400] "POST 
/mylimo/+/limoService.Driver%3D HTTP/1.1" 500 84 
"http://localhost:2020/mylimo/+/limoService.Driver="; "Mozilla/5.0 (Windows; U; 
Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11"
from zope.app import zapi
from zope.interface import implements
from zope.app.container.btree import BTreeContainer
from zope.app.container.contained import Contained
# from persistent import Persistent

from interfaces import ICar, IDriver, ILimoservice, ILimoserviceContained

class Car(Contained):
        implements(ICar,ILimoserviceContained)
        model=u''
        nPassengers=0

class Driver(Contained):
        implements(IDriver,ILimoserviceContained)
        car=None

class Limoservice(BTreeContainer):
        implements(ILimoservice)

class CarView(object):
    def message(self):
        return 'car model %s holds %d passengers' % (self.context.model, 
self.context.nPassengers)
class DriverView(object):
        def message(self):
                if self.context.car:
                        car=self.context.car
                        msg='driver drives car model %s, can carry %d 
passengers' % (car.model,car.nPassengers)
                else:
                        print 'driver has no car!'
                        msg='no car info'
                return msg

from zope.formlib import form
class CarEdit(form.EditForm):
        form_fields = form.Fields(ICar)
class DriverEdit(form.EditForm):
        form_fields = form.Fields(IDriver)

class CarAddForm(form.AddForm):
        form_fields = form.Fields(ICar)
        def create(self,data):
                obj=Car()
                form.applyChanges(obj, self.form_fields, data)
                return obj
class DriverAddForm(form.AddForm):
        form_fields = form.Fields(IDriver)
        def create(self,data):
                obj=Driver()
                form.applyChanges(obj, self.form_fields, data)
                return obj

from zope.schema.vocabulary import SimpleVocabulary
def carsInParent(context):
    '''returns child cars __name__ for subobjects of parent as a vocabulary'''
    return SimpleVocabulary.fromItems(
        [(k, v) for k, v in context.__parent__.items() if ICar.providedBy(v)])

<configure
    xmlns="http://namespaces.zope.org/zope";
    xmlns:browser="http://namespaces.zope.org/browser";
        i18n_domain="limoService"
        >
        
  <interface
      interface=".interfaces.ICar"
      type="zope.app.content.interfaces.IContentType"
      />
  <interface
      interface=".interfaces.IDriver"
      type="zope.app.content.interfaces.IContentType"
      />

  <class class=".classes.Car">
    <implements
        interface="zope.annotation.interfaces.IAttributeAnnotatable"
        />
    <factory
        id="limoService.classes.Car"
        description="a car" 
        />
    <require
        permission="zope.Public"
        interface=".interfaces.ICar"
        />
    <require
        permission="zope.ManageContent"
        set_schema=".interfaces.ICar"
        />
  </class>
  <class class=".classes.Driver">
    <implements
        interface="zope.annotation.interfaces.IAttributeAnnotatable"
        />
    <factory
        id="limoService.classes.Driver"
        description="a driver" 
        />
    <require
        permission="zope.Public"
        interface=".interfaces.IDriver"
        />
    <require
        permission="zope.ManageContent"
        set_schema=".interfaces.IDriver"
        />
  </class>

  <browser:addMenuItem
      class=".classes.Car"
      title="a car"
      view=".Car"
      permission="zope.ManageContent"
      description="add Car"
  />
  <browser:addMenuItem
      class=".classes.Driver"
      title="a driver"
      view=".Driver"
      permission="zope.ManageContent"
      description="add Driver"
  />

  <browser:page
    for="zope.app.container.interfaces.IAdding"
    name=".Car"
    class=".classes.CarAddForm"
    permission="zope.ManageContent"
    />
  <browser:page
    for="zope.app.container.interfaces.IAdding"
    name=".Driver"
    class=".classes.DriverAddForm"
    permission="zope.ManageContent"
    />

  <browser:page
      for=".interfaces.ICar"
      name="index.html"
      class=".classes.CarView"
      permission="zope.Public"
          template="read.pt"
          menu="zmi_views" title="view"
      />
  <browser:page
      for=".interfaces.IDriver"
      name="index.html"
      class=".classes.DriverView"
      permission="zope.Public"
          template="read.pt"
          menu="zmi_views" title="view"
      />

  <browser:page
      for=".interfaces.ICar"
      name="edit.html"
      class=".classes.CarEdit"
      permission="zope.ManageContent"
      template="edit.pt"
          menu="zmi_views" title="edit"
      />
  <browser:page
      for=".interfaces.IDriver"
      name="edit.html"
      class=".classes.DriverEdit"
      permission="zope.ManageContent"
      template="edit.pt"
          menu="zmi_views" title="edit"
          />

  <utility
      provides="zope.schema.interfaces.IVocabularyFactory"
      component=".classes.carsInParent"
      name="allCars"
      />

  <interface
      interface=".interfaces.ILimoservice"
      type="zope.app.content.interfaces.IContentType"
      />
  
  <class class=".classes.Limoservice">
    <implements
        interface="zope.app.annotation.interfaces.IAttributeAnnotatable"
        />
    <implements
        interface="zope.app.container.interfaces.IContentContainer" 
        />
    <factory
        id="limoService.classes.Limoservice"
        description="Limoservice" 
        />
    <require
        permission="zope.ManageContent"
        interface=".interfaces.ILimoservice"
        />
    <require
        permission="zope.ManageContent"
        set_schema=".interfaces.ILimoservice"
        />
  </class>
  
  <browser:addMenuItem
      class=".classes.Limoservice"
      title="Limoservice"
      permission="zope.ManageContent"
  />
  <browser:containerViews
      for="limoService.interfaces.ILimoservice"
      index="zope.View"
      contents="zope.View"
      add="zope.ManageContent"
      />

  </configure>
from zope.interface import Interface
from zope.schema import Field, Text, TextLine, Choice, Int, Bool, Date, 
Datetime, Object
from zope.schema.vocabulary import SimpleVocabulary

from zope.app.container.constraints import ContainerTypesConstraint
from zope.app.container.constraints import ItemTypePrecondition
from zope.app.container.interfaces import IContained, IContainer

class ICar(Interface):
        model = TextLine(
                title = u'model',
                description = u'model',
                default = u'',
                required = False)
        nPassengers = Int(
                title = u'nPassengers',
                description = u'nPassengers',
                default = 0,
                required = False)

class IDriver(Interface):
        car = Choice(
                title = u'car',
                description = u'car',
                default = None,
                source = 'allCars',
                required = False)

class ILimoservice(IContainer):
        '''container for items of type ICar, IDriver'''
        name = TextLine(
                title=u'Limoservice',
                description=u'a Limoservice container',
                default=u'',
                required=True)
        def __setitem__(name, obj): pass 
        __setitem__.precondition = ItemTypePrecondition(ICar, IDriver)

class ILimoserviceContained(IContained):
        '''for types that can only be contained in a Limoservice'''
        __parent__ = Field(constraint = ContainerTypesConstraint(ILimoservice))
_______________________________________________
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users

Reply via email to