[Zope3-Users] Re: zc.table - how does sorting work?
Laurence Rowe
l at lrowe.co.uk
Tue Mar 14 14:08:34 EST 2006
Once I added the package includes, adding
for c in columns:
directlyProvides(c, zc.table.interfaces.ISortableColumn)
did the trick.
I'd love to have a look at your alternate sorting implementation, though
will need to get checking privileges before merging. (I'll look into
applying for these).
Many thanks,
Laurence
Gary Poster wrote:
>
> On Mar 14, 2006, at 11:54 AM, Laurence Rowe wrote:
>
>> Hi there,
>>
>> I'm trying to use zc.table to format the output of one of my forms. it
>> seems to work ok for the unsorted formatter, but not for the
>> StandalonSortFormatter. Here is the code that works with plain formatter:
>>
>>> columns = (
>>> GetterColumn(name=u'dn', title=u'Distinguished Name',
>>> getter=lambda i, f: i.dn, subsort=True),
>>> GetterColumn(name=u'displayName', title=u'Name', getter=lambda i,
>>> f: i.displayName, subsort=True),
>>> GetterColumn(name=u'mail', title=u'Email Address', getter=lambda
>>> i, f: i.mail, subsort=True),
>>> )
>>> class LDAPFilterForm(form.Form):
>>> form_fields = form.Fields(interfaces.ILDAPFilter)
>>> @form.action("Search")
>>> def handle_search_action(self, action, data):
>>> search = interfaces.ILDAPSearch(self.context, None)
>>> results = search.search(data['filter'])
>>> self.table = table.Formatter(self.context, self.request,
>>> list(results), columns=columns)
>>> return self.table()
>>
>> but when I change the Formatter to StandaloneSortFormatter, I still
>> get the same html output. I have tried adding in this from the
>> zc.table readme:
>>
>>> for c in columns:
>>> directlyProvides(c, zc.table.interfaces.ISortableColumn)
>
> Yes, you want this.
>
>>> @adapter(IRequest)
>>> @implementer(Interface)
>>> def dummyResource(request):
>>> return lambda:'/@@/zc.table'
>>> provideAdapter(dummyResource, name='zc.table')
>
> No, you don't want this.
>
>> But then I get the following traceback:
>>
>>> 2006-03-14T16:34:32 ERROR SiteError http://localhost:8080/@@/zc.table
>>> Traceback (most recent call last):
>>> File "/usr/lib/python2.4/site-packages/zope/publisher/publish.py",
>>> line 135, in publish
>>> object = request.traverse(object)
>>> File "/usr/lib/python2.4/site-packages/zope/publisher/browser.py",
>>> line 500, in traverse
>>> ob = super(BrowserRequest, self).traverse(object)
>>> File "/usr/lib/python2.4/site-packages/zope/publisher/http.py",
>>> line 451, in traverse
>>> ob = super(HTTPRequest, self).traverse(object)
>>> File "/usr/lib/python2.4/site-packages/zope/publisher/base.py",
>>> line 289, in traverse
>>> subobject = publication.traverseName(
>>> File
>>> "/usr/lib/python2.4/site-packages/zope/app/publication/publicationtraverse.py",
>>> line 56, in traverseName
>>> ob2 = ob.publishTraverse(request, nm)
>>> File
>>> "/usr/lib/python2.4/site-packages/zope/app/publisher/browser/resources.py",
>>> line 40, in publishTraverse
>>> locate(resource, sm, name)
>>> File
>>> "/usr/lib/python2.4/site-packages/zope/app/location/location.py",
>>> line 72, in locate
>>> object.__name__ = name
>>> TypeError: func_name must be set to a string object
>>> exceptions.TypeError:
>>> func_name must be set to a string object
>>>> /usr/lib/python2.4/site-packages/zope/app/location/location.py(72)locate()
>>>>
>>> -> object.__name__ = name
>>
>> Using the debugger I can see:
>>
>>> (Pdb) name
>>> u'zc.table
>>
>> Any ideas? I'm stumped.
>
> Not sure, but I'm guessing it is the dummy adapter. Try again without it.
>
> Also, as I wrote yesterday, we have an alternate sorting implementation
> that we ought to get in zc.table. I sent it to Martijn Faassen; if you
> think you might look at it and maybe merge it, I could send it to you
> too. :-)
>
> Gary
More information about the Zope3-users
mailing list