[Zope3-Users] Re: How to register a local adapter?
andy chen
backrain at gmail.com
Sun Jan 6 22:08:16 EST 2008
hi,
I think you goes wrong way,All you have done is just like Christophe said:
"create an IMyFolder interface, implemented by MyFolder
as a subclass of Folder (nothing more), then to register an index.html for
IMyFolder."
and maybe "containerViews" zcml directive will help you.
however,if you stand on your way,try this:
from zope.security.checker import CheckerPublic, Checker, defineChecker
@adapter(IDatabaseOpenedWithRootEvent)def RegisterLocalPage(event):
# security setting
required = {}
for n in ( 'browserDefault', '__call__', 'publishTraverse'):
required[n] = CheckerPublic
defineChecker(NewFolderIndex, Checker(required))
db, conn, root, root_folder = getInformationFromEvent(event)
for city in root_folder:
sm = root_folder[city].getSiteManager()
sm.registerAdapter(NewFolderIndex, [IFolder, IMyLayer], IBrowserPage,
'index.html')
transaction.commit() conn.close()
On Jan 6, 2008 10:19 PM, nixon <nxnth at yahoo.com.cn> wrote:
> Thank you, Christophe!
>
> I write code according to your FAQ, but an error occurs.
> My code is:
>
> class NewFolderIndex(BrowserPage):
> #adapts(IFolder, IMyLayer)
>
> #__call__ = ViewPageTemplateFile('skin/test.pt')
> def __call__(self):
> self.request.response.setHeader('Content-Type', 'text/plain')
> return self.context.name
>
> @adapter(IDatabaseOpenedWithRootEvent)
> def RegisterLocalPage(event):
> db, conn, root, root_folder = getInformationFromEvent(event)
> for city in root_folder:
> sm = root_folder[city].getSiteManager()
> sm.registerAdapter(NewFolderIndex, [IFolder, IMyLayer], IBrowserPage, 'index.html')
> transaction.commit()
> conn.close()
>
> Zope starts up without any issue. But when I access the 'index.html', an error occurs:
>
> Traceback (most recent call last):
> File "D:\wp\Python24\Lib\site-packages\zope\publisher\publish.py", line 130, i
> n publish
> obj =
> request.traverse(obj)
> File "D:\wp\Python24\Lib\site-packages\zope\publisher\browser.py", line 527, i
> n traverse
> ob, add_steps = publication.getDefaultTraversal(self, ob)
> File "D:\wp\Python24\Lib\site-packages\zope\app\publication\browser.py", line
> 66, in getDefaultTraversal
> return ob.browserDefault(request)
> ForbiddenAttribute: ('browserDefault', <mailnice.reglocalpage.NewFolderIndex obj
> ect at 0x027F8BF0>)
>
> I dont know why. It seems the inherited BrowserPage.browserDefault is available.
>
> Thank you!
> R Nixon
>
> ------------------------------
> ÑÅ»¢ÓÊÏä´«µÝÐÂÄê×£¸££¬¸öÐԺؿ¨ËÍÇ×Åó£¡<http://cn.mail.yahoo.com/gc/index.html?entry=5&souce=mail_mailletter_tagline>
>
>
> _______________________________________________
> Zope3-users mailing list
> Zope3-users at zope.org
> http://mail.zope.org/mailman/listinfo/zope3-users
>
>
--
cheers
best regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/zope3-users/attachments/20080107/d086f085/attachment.htm
More information about the Zope3-users
mailing list