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:
Traceback (innermost last):
Module ZPublisher.Publish, line 116, in publish
Module ZPublisher.BaseRequest, line 498, in traverse
Module ZPublisher.BaseRequest, line 343, in traverseName
Module ZPublisher.BaseRequest, line 110, in publishTraverse
Module zope.component._api, line 122, in queryMultiAdapter
Module zope.component.registry, line 240, in queryMultiAdapter
Module zope.interface.adapter, line 522, in queryMultiAdapter
TypeError:__init__() takes exactly 2 arguments (3 given)
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). At any rate here’s what my BrowserView class looks like at the moment:
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.
I’m testing this in a Plone 4.0.2 site on Mac OS X Snow Leopard (in a python 2.6.6 virtualenv)
BrowersView registration from browser/configure.zcml (I threw this into a theme I was also working with). I call http://localhost:8080/plone/events/new_events_view to see how the view looks and get the above error. 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.
<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
You shouldn’t put any code in the
__init__method of a browser view anyways. If you want to have some custom code put it into methods on the view class or overwrite the__call__method. 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: