简体   繁体   English

Plone 4表格视图变通

[英]Plone 4 Table View Work Around

I'm writing a custom view to get around the bug that displays the wrong start and end times for events in table view in Plone 4. However, when I call my view I get the following error: 我正在编写一个自定义视图,以解决在Plone 4的表视图中显示错误的事件开始和结束时间的错误。但是,当我调用视图时,出现以下错误:

Traceback (innermost last): 追溯(最里面的最后):
Module ZPublisher.Publish, line 116, in publish 模块ZPublisher.Publish,行116,在publish中
Module ZPublisher.BaseRequest, line 498, in traverse 遍历模块ZPublisher.BaseRequest,第498行
Module ZPublisher.BaseRequest, line 343, in traverseName traverseName中的模块ZPublisher.BaseRequest,第343行
Module ZPublisher.BaseRequest, line 110, in publishTraverse publishTraverse中的模块ZPublisher.BaseRequest,第110行
Module zope.component._api, line 122, in queryMultiAdapter queryMultiAdapter中的模块zope.component._api,第122行
Module zope.component.registry, line 240, in queryMultiAdapter queryMultiAdapter中的模块zope.component.registry,第240行
Module zope.interface.adapter, line 522, in queryMultiAdapter queryMultiAdapter中的模块zope.interface.adapter,第522行
TypeError: __init__ () takes exactly 2 arguments (3 given) TypeError: __init__ ()恰好接受2个参数(给定3个)

It's been awhile since I've created a view, but I thought (in accordance with this ) that __init__() does take 3 arguments (self, context, request). 自从创建视图以来已经有一段时间了,但是我认为__init__()确实接受3个参数(self,context,request)(根据观点)。 At any rate here's what my BrowserView class looks like at the moment: 无论如何,这是我的BrowserView类当前的样子:

class NewEventsView(BrowserView):
    """Custom View for displaying events in a table with correct times"""

    implements(INewEventsView)

    def getCurrentEvents(self):
        """Method to return all active events in order"""
        current_events = []
        cat = getToolByName(self.context, 'portal_catalog')
        brains = cat(portal_type='Event', review_state='published', sort_on='start')
        for x in brains:
            event = x.getObject()
            if event.startDate > DateTime():
                current_events.append(event)
        return current_events

I've tried different variations of this adding an __init__ as in the above mentioned page shows, and just for the heck of it giving it an __init__(self, context): just to see if 2 arguments would really change anything and it gives the exact same error. 我尝试了不同的变体,如上面提到的页面所示,添加了一个__init__ ,只是为了给它一个__init__(self, context):而已__init__(self, context):仅查看2个参数是否真的会改变任何东西,并且给出完全相同的错误。

I'm testing this in a Plone 4.0.2 site on Mac OS X Snow Leopard (in a python 2.6.6 virtualenv) 我正在Mac OS X Snow Leopard上的Plone 4.0.2站点(在python 2.6.6 virtualenv中)中对此进行测试。

BrowersView registration from browser/configure.zcml (I threw this into a theme I was also working with). BrowersView从browser / configure.zcml进行注册(我把它变成了我也在使用的主题)。 I call http://localhost:8080/plone/events/new_events_view to see how the view looks and get the above error. 我调用http:// localhost:8080 / plone / events / new_events_view来查看视图外观并得到上述错误。 I've also tried registering the view in portal_types for topic and it will give me that error upon navigating to http://localhost:8080/plone/events until I remove the view. 我还尝试过在主题的portal_types中注册视图,并且导航到http:// localhost:8080 / plone / events直到我删除视图,这都会给我该错误。

  <browser:page
      for="*"
      name="new_events_view"
      class=".newEventsView.NewEventsView"
      template="newEventsView.pt"
      permission="zope.Public"
      allowed_interface=".interfaces.INewEventsView"
      />

Any help would be greatly appreciated. 任何帮助将不胜感激。

Also, I know it's a small block of code, but rip it apart if you think it could be done in a better fashion, I'm a student always looking for ways to improve. 另外,我知道这只是一小段代码,但是如果您认为可以以更好的方式完成,请把它拆开,我一直在寻找改进的方法。

Thanks 谢谢

A much better workaround would be to customize the formatCatalogMetadata.py skin script from the ATContentTypes skin layer. 更好的解决方法是从ATContentTypes外观层自定义formatCatalogMetadata.py外观脚本。

Replace the line reading: 替换行读数:

if same_type(value, '') and value[4:-1:3] == '-- ::':

with: 与:

if same_type(value, '') and (value[4:-1:3] == '-- ::' or value[4:19:3] == '--T::'):

and the event view tables work again for events. 事件视图表将再次用于事件。

You shouldn't put any code in the __init__ method of a browser view anyways. 无论如何,您都不应在浏览器视图的__init__方法中放置任何代码。 If you want to have some custom code put it into methods on the view class or overwrite the __call__ method. 如果要使用一些自定义代码,请将其放入视图类的方法中或覆盖__call__方法。 The view is instantiated before a security context is available and might be instantiated multiple times per request. 该视图在安全上下文可用之前被实例化,并且每个请求可能被实例化多次。 This can lead to a lot of surprising effects if you do any non-trivial work in it - so best just avoid doing anything in there. 如果您在其中进行任何不重要的工作,这可能会导致很多令人惊讶的效果-因此最好避免在其中进行任何操作。

In Plone 4 you would write a custom __call__ as: 在Plone 4中,您可以将自定义__call__编写为:

from zope.publisher.browser import BrowserView

class MyView(BrowserView):

    def __call__(self):
        # do some work
        return super(MyView, self).__call__()

But it's python ! 但这是python

The definition for a class method is: 类方法的定义是:

def __init__(context, request):

self is understood by default (because the method is called as Class.__init__(context,request) ) (or, again, shortened to Class() ). 默认情况下会理解self (因为该方法称为Class.__init__(context,request) )(或者再次简称为Class() )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM