[Zope] ZPT getFiles() from Python
Peter Bengtsson
mail@peterbe.com
Fri, 26 Apr 2002 11:51:23 +0100
At 05:11 2002-04-26 +0200, Roger Ineichen wrote:
>Hello
>I have a problem with to port a PythonScript to Python. How can I use
>this in a Python Method the Python
>The ZPT looks like:
>_________________
>
><div tal:define="sort request/sort|string:id;
> reverse request/reverse|python:0;
> files python:here.getFiles(sort, reverse);
> start request/start|python:0;
> batch python:modules['ZTUtils'].Batch(files,
>size=8, start=start);
> previous python:batch.previous;
> next python:batch.next">
>_________________
>
>
>Python Script looks like: getFiles(self, sort='id', reverse=0)
>_________________
>"""
>Returns a list of files sorted by id, date, type or size.
>"""
>files=container.objectValues('File')
>
>[...]
>
>
>return sequence.sort(files, args)
>_________________
>
>How can I use the ZPT with a Python Method like: "def getFiles(self,
>sort='id', reverse=0)"
>How can I use sequence (with ZTUtils?)
You don't put 'self' as a parameter of a Python Script.
This 'll be how you do it:
from DocumentTemplate import sequence
def getFiles(self, sort='id', reverse=0):
files = self.objectValues('File')
[...]
return sequence.sort(files, args)
The batching stuff you do in the template and let the External Method just
handle the getting of the files only.
Otherwise, to import the batching, here's how:
from ZTUtils.Batch import Batch