[Zope3-Users] Fields for file and images
James Allwyn
jamesallwyn at gmail.com
Mon Oct 24 08:32:33 EDT 2005
I too have been getting "UnpickleableError" while playing with ObjectWidgets.
I've been working from some code posted by Christian Lueck (Fri, 26
Aug 2005, subject "[Zope3-Users] zope.schema.Object - Object of
Objects").
Christian's example had an object "Nonsens Article", which included a
sub-object "Article", which itself included a couple of further
sub-objects, "Person" and "Pages"). I slimmed this down to just two
layers - "Article" and its sub-objects (i.e. I stripped out the
Nonsens Article super-object).
(Code follows at end)
Now, creating an Article works fine. Editing it works fine. But
deleting it after Editing causes the error:
Exception Type
UnpickleableError
Exception Value
Cannot pickle <type 'zope.security._proxy._Proxy'> objects
If I restart Zope after editing the Article I can delete it.
Any suggestions on how to tackle this? Unlike the poll example that
Johan was working from, Christian's 'objectsofobjects' demo does not
include get and set methods - is it recommended to introduce them to
use removeSecurityProxy stripping to handle this?
Thanks,
James
Code
----
Below is the code (adapted from Christian's objectsofobjects demo).
interfaces.py
------------------
from zope.interface import Interface
from zope.schema import TextLine, Int, Object
class IPerson(Interface):
lastname = TextLine(
title=u"Lastname",
description=u"Please give the lastname.",
required=False)
firstname = TextLine(
title=u"Firstname",
description=u"Please give the firstname.",
required=False)
class IPages(Interface):
start = Int(
title=u"Start page",
description=u"Please give the start page.",
required=False)
end = Int(
title=u"End page",
description=u"Please give the end page.",
required=False)
class IArticle(Interface):
author = Object(
schema=IPerson,
title=u"Author",
description=u"The author of the article.",
required=False)
title = TextLine(
title=u"Article title",
description=u"Please give the title of the article.",
required=False)
pages = Object(
schema=IPages,
title=u"Pages",
description=u"Start and end page of the article.",
required=False)
article.py
-------------
from zope.interface import implements
from interfaces import IPerson, IPages, IArticle
from zope.schema.fieldproperty import FieldProperty
class Person:
"""The Person object."""
implements(IPerson)
class Pages:
"""The Pages object."""
implements(IPages)
class Article:
"""The article object."""
pages = FieldProperty(IArticle['pages'])
author = FieldProperty(IArticle['author'])
implements(IArticle)
widget.py
--------------
from zope.app.form.browser.editview import EditView
from zope.app.form import CustomWidgetFactory
from zope.app.form.browser import ObjectWidget
from interfaces import IArticle
from article import Person, Pages, Article
class ArticleEditView(EditView):
__used_for__ = IArticle
author_widget = CustomWidgetFactory(ObjectWidget, Person)
pages_widget = CustomWidgetFactory(ObjectWidget, Pages)
configure.zcml
----------------------
<configure
xmlns='http://namespaces.zope.org/zope'
xmlns:browser='http://namespaces.zope.org/browser'>
<content class=".article.Person">
<require
permission="zope.View"
interface=".interfaces.IPerson"
/>
<require
permission="zope.ManageContent"
set_schema=".interfaces.IPerson"
/>
</content>
<content class=".article.Pages">
<require
permission="zope.View"
interface=".interfaces.IPages"
/>
<require
permission="zope.ManageContent"
set_schema=".interfaces.IPages"
/>
</content>
<content class=".article.Article">
<require
permission="zope.View"
interface=".interfaces.IArticle"
/>
<require
permission="zope.ManageContent"
set_schema=".interfaces.IArticle"
/>
</content>
<browser:editform
label="Change article data"
name="edit.html"
schema=".interfaces.IArticle"
class=".widget.ArticleEditView"
menu="zmi_views"
title="Edit"
permission="zope.ManageContent"
/>
<browser:addform
label="Add an article"
name="AddArticle.html"
schema=".interfaces.IArticle"
class=".widget.ArticleEditView"
content_factory=".article.Article"
permission="zope.ManageContent"
/>
<browser:addMenuItem
title="Article"
class=".article.Article"
permission="zope.ManageContent"
view="AddArticle.html"
/>
</configure>
On 20/10/05, Johan Carlsson <johanc at easypublisher.com> wrote:
> Johan Carlsson wrote:
>
> For anyone that might be interested in the update to my code (still only
> parsely working):
>
> > 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.security.proxy import removeSecurityProxy
>
> > 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)
> >
>
> def get_file(self):
> return self._file
>
> def set_file(self, file):
> self._file = removeSecurityProxy(file)
>
> file = property(get_file, set_file, None, 'fiddle file')
>
>
> >
> > 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
>
>
> --
> 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
>
> _______________________________________________
> Zope3-users mailing list
> Zope3-users at zope.org
> http://mail.zope.org/mailman/listinfo/zope3-users
>
More information about the Zope3-users
mailing list