[Zope3-Users] Re: How to extend File?
jürgen Kartnaller
j.kartnaller at cable.vol.at
Sat Nov 20 03:25:50 EST 2004
Here is the code I used for testing :
---------------------------------------------------------------
f.py :
from zope.interface import Interface,implements
from zope.app.file.file import File
from zope.schema import TextLine
from zope.i18nmessageid import MessageIDFactory
_ = MessageIDFactory("test")
class IContentGuid(Interface):
guid = TextLine(title=_('guid desc'))
class ContentBase(File):
implements(IContentGuid)
---------------------------------------------------------------
configure.zcml :
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
i18n_domain='test'
>
<interface
interface=".f.IContentGuid"
type="zope.app.content.interfaces.IContentType"
/>
<content class=".f.ContentBase">
<implements
interface="zope.app.annotation.interfaces.IAttributeAnnotatable"
/>
<factory
id="test.f.ContentBase"
description="ContentBase"
/>
<require
permission="zope.ManageContent"
interface=".f.IContentGuid"
/>
<require
permission="zope.ManageContent"
set_schema=".f.IContentGuid"
/>
</content>
<browser:addform
label="ContentBase hinzufuegen"
name="AddContentBase.html"
schema="test.f.IContentGuid"
content_factory="test.f.ContentBase"
permission="zope.ManageContent"
/>
<browser:addMenuItem
class="test.f.ContentBase"
title="ContentBase"
description="A ContentBase"
permission="zope.ManageContent"
view="AddContentBase.html"
/>
<browser:editform
schema="test.f.IContentGuid"
for="test.f.IContentGuid"
label="Change ContentBase"
name="edit.html"
permission="zope.ManageContent"
menu="zmi_views" title="Edit"
/>
</configure>
Hope this helps.
Jürgen
John Toews wrote:
> With essentially the code below (I forgot the guid = '' in ContentBase) and the proper includes, I used the browser:addMenuItem directive in my configure.zcml. I can add an item but not manage it (clicking on it results in a ForbiddenAttribute error for 'contentType' on ContentBase).
>
> I am wondering if I should be using the content directive in the zcml?
>
> Or if I need my own __init__ in ContentBase?
>
> Thanks!
>
> -----Original Message-----
> From: zope3-users-bounces at zope.org [mailto:zope3-users-bounces at zope.org] On Behalf Of jürgen Kartnaller
> Sent: Thursday, November 18, 2004 2:00 PM
> To: zope3-users at zope.org
> Subject: [Zope3-Users] Re: How to extend File?
>
> This works well for me.
> I used a configure.zcml by following Stephan Richters Zope 3 book.
> I'm now able to add a new file object with a guid field.
>
> You should give us the traceback of the system error.
>
> Jürgen
>
> John Toews wrote:
>
>>Hi all,
>>
>>I'm trying to do something I thought would be very simple. I think I
>>don't understand the Component Architecture well enough...
>>
>>I want to take the base File and simply add a property to it (a string
>>representing a guid). That's all, everything else would remain the same.
>>I've tried a couple different ways of doing:
>>
>>class IContentGuid(Interface):
>> guid = TextLine(title=_('guid desc'))
>>
>>class ContentBase(File):
>> zope.interface.implements(IContentGuid)
>>
>>And various configure.zcml setups. I can't really explain what's going
>>wrong either. The best I've gotten is a link in the ZMI to
>>ContentBase, which when clicked on will add an item, but after typing
>>in a name and hitting Apply, a system error occurs. I think I'm just
>>on the wrong track.
>>
>>Any ideas on what (all) I'm doing wrong?
>>Thanks!
>>John
>
>
> _______________________________________________
> 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