[Zope3-Users] Fields for file and images

Johan Carlsson johanc at easypublisher.com
Thu Oct 20 10:16:58 EDT 2005


Hi all,
I'm trying to figure out the easiest way to get fields holding Files or 
Images in my content type class.


I've tried the following:
I've tried using the Object field specifying the 
zope.app.file.interfaces.IFile as the schema and then
implement a CustomWidgetFactory with zope.app.file.file.File
as the factory.

This actually looks ok both in the AddView and the EditView
but the updates fail (due to cPickle.UnpickleableError: Cannot pickle 
<type 'zope.security._proxy._Proxy'> objects, which sounds like the
File object needs to be removed from it's proxy somewhere in the chain?)

Any thought on how to solve this problem (my approach or other approach)?

Regards,
Johan


Here is my code (which uses the Poll as base, that stuff has been 
removed though):

interfaces.py:

   from zope.interface import Interface
   from zope.schema import Object
   from zope.app.file.interfaces import IFile

   from zope.i18n import MessageIDFactory
   _ = MessageIDFactory('poll')

   class IPoll(Interface):

       file=Object(IFile, title=_('File'))

poll.py:

   from persistent import Persistent
   from interfaces import IPoll
   from zope.interface import implements, classImplements
   from zope.app.file.file import File

   class Poll(Persistent, object):
       implements(IPoll)

       file=None


browser.py:

   from zope.interface import implements
   from zope.app.form.browser.editview import EditView
   from zope.app.form.browser.add import AddView
   from zope.app.form import CustomWidgetFactory
   from zope.app.form.browser import ObjectWidget

   from interfaces import IPoll


   from zope.app.file.file import File

   fw = CustomWidgetFactory(ObjectWidget, File)

   class PollEditView(EditView):
       __used_for__ = IPoll

       file_widget = fw

   class PollAddView(AddView):
       __used_for__ = IPoll

       file_widget = fw

configure.zcml:

<configure xmlns="http://namespaces.zope.org/zope"
     xmlns:browser="http://namespaces.zope.org/browser"
     i18n_domain="poll">

   <content class=".poll.Poll">
   <factory id="zope.app.demo.poll2" />

   <implements
     interface="zope.app.annotation.interfaces.IAttributeAnnotatable"
     />

   <require
     permission="zope.View"
     interface=".interfaces.IPoll"
     />

   <require
     permission="zope.ManageContent"
     set_schema=".interfaces.IPoll"
     />
   </content>

   <browser:addform
     schema=".interfaces.IPoll"
     label="Add a Poll"
     content_factory=".poll.Poll"
     name="AddPoll2.html"
     class=".browser.PollAddView"
     permission="zope.ManageContent" />

   <browser:addMenuItem
     title="Poll 2 Demo"
     description="Poll 2 Demo"
     class=".poll.Poll"
     view="AddPoll2.html"
     permission="zope.ManageContent"
     />

   <browser:editform
     schema=".interfaces.IPoll"
     class=".browser.PollEditView"
     label="Change a Poll"
     name="edit.html"
     menu="zmi_views" title="Edit"
     permission="zope.ManageContent" />
</configure>




-- 
Johan Carlsson          Tel: + 46 8 31 24 94
Colliberty              Mob: + 46 70 558 25 24
Torsgatan 72            Email: johanc at easypublisher.com
SE-113 37 STOCKHOLM



More information about the Zope3-users mailing list