簡體   English   中英

Plone / Zope / Z3c-是什么原因導致publishTraverse找不到頁面?

[英]Plone/Zope/Z3c- What can cause publishTraverse to “not find the page?”

我正在嘗試獲取z3c form.Form來填寫其信息,而不是在url中創建get參數,我想使用publishTraverse。

所以這是我的代碼的一部分:

my_object_view.py:

class EditMyObject(form.Form):
   fields = field.Fields(IMyObject)
   ignoreContext = False

   myObjectID = None

   def publishTraverse(self, request, name):
       print "Is this firing?"
       if self.myObjectID is None:
           self.myObjectID = name
           return self
       else:
           raise NotFound()

   def updateWidgets(self):
       super(EditMyObject,self).updateWidgets()
       #set id field's mode to hidden

   def getContent(self):

       db_utility = queryUtility(IMyObjectDBUtility, name="myObjectDBUtility")
       return db_utility.session.query(MyObject).filter(MyObject.My_Object_ID==self.myObjectID).one()

   #Button handlers for dealing with form also added

.....
from plone.z3cform.layout import wrap_form
EditMyObjectView = wrap_form(EditMyObject)    

在我的configure.zcml文件的瀏覽器文件夾中:

<configure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:five="http://namespaces.zope.org/five"
    xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
    xmlns:zcml="http://namespaces.zope.org/zcml"
    xmlns:browser="http://namespaces.zope.org/browser"
    i18n_domain="my.object">

    <browser:page
        name="myobject-editform"
        for="*"
        permission="zope2.View"
        class=".my_object_view.EditMyObjectView"
    />

</configure>

當我在URL中使用get參數時,我能夠使它工作,但是當我嘗試使用publishTraverse時,出現頁面未找到錯誤。 奇怪的是,什么時候

當我嘗試使用發布遍歷時,這就是我的網址的樣子:

http://localhost:8190/MyPloneSite/@@myobject-editform/1

當我忽略1時,但保留“ /”,它仍然會找到該頁面。 我做錯了什么導致這個?

除非您聲明該視圖提供了IPublishTraverse接口,否則Zope發布者將不會調用publishTraverse。 您需要將此添加到您的班級:

from zope.publisher.interfaces.browser import IPublishTraverse
from zope.interface import implementer

@implementer(IPublishTraverse)
class EditMyObject(form.Form):
    etc...

您還需要擺脫包裝器視圖。 使用包裝器,Zope遍歷到包裝器,檢查它是否提供IPublishTraverse,發現它沒有提供,然后放棄。 相反,只需將表單直接注冊為視圖:

<browser:page
    name="myobject-editform"
    for="*"
    permission="zope2.View"
    class=".my_object_view.EditMyObject"
/>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM