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') # build arguments for sequence.sort if sort=='id': if not reverse: args=(('getId',),) else: args=(('getId', 'cmp', 'desc'),) elif sort=='date': if not reverse: args=(('bobobase_modification_time',), ('getId',)) else: args=(('bobobase_modification_time', 'cmp', 'desc'), ('getId',)) elif sort=='type': if not reverse: args=(('getContentType',), ('getId',)) else: args=(('getContentType', 'cmp', 'desc'), ('getId',)) elif sort=='size': if not reverse: args=(('getSize', 'cmp', 'desc'), ('getId',)) else: args=(('getSize',), ('getId',)) 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?) Thanks Roger Ineichen ___________________________ Projekt01 GmbH www.projekt01.ch Langackerstrasse 8 6330 Cham phone +41 (0)41 781 01 78 mobile +41 (0)79 340 52 32 fax +41 (0)41 781 00 78 email r.ineichen@projekt01.ch ___________________________ END OF MESSAGE
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
Roger Ineichen writes:
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) You did not pass an argument for "self".
Either remove the "self" from the "parameters" list or pass "here". Dieter
participants (3)
-
Dieter Maurer -
Peter Bengtsson -
Roger Ineichen