Commit 3fa0fa56 authored by Shane Hathaway's avatar Shane Hathaway

Multiple sort fields for dtml-in. Modified patch from collector #1172.

parent 09e6a202
...@@ -382,12 +382,12 @@ ...@@ -382,12 +382,12 @@
''' #' ''' #'
__rcs_id__='$Id: DT_In.py,v 1.39 2000/05/11 18:54:14 jim Exp $' __rcs_id__='$Id: DT_In.py,v 1.40 2000/05/25 16:33:44 shane Exp $'
__version__='$Revision: 1.39 $'[11:-2] __version__='$Revision: 1.40 $'[11:-2]
from DT_Util import ParseError, parse_params, name_param, str from DT_Util import ParseError, parse_params, name_param, str
from DT_Util import render_blocks, InstanceDict, ValidationError from DT_Util import render_blocks, InstanceDict, ValidationError
from string import find, atoi, join from string import find, atoi, join, split
import ts_regex import ts_regex
from DT_InSV import sequence_variables, opt from DT_InSV import sequence_variables, opt
TupleType=type(()) TupleType=type(())
...@@ -702,12 +702,18 @@ class InClass: ...@@ -702,12 +702,18 @@ class InClass:
def sort_sequence(self, sequence): def sort_sequence(self, sequence):
# Modified with multiple sort fields by Ross Lazarus
# April 7 2000 rossl@med.usyd.edu.au
# eg <dtml in "foo" sort=akey,anotherkey>
sort=self.sort sort=self.sort
sortfields = split(sort,',') # multi sort = key1,key2
multsort = len(sortfields) > 1 # flag: is multiple sort
mapping=self.mapping mapping=self.mapping
isort=not sort isort=not sort
k=None
s=[] s=[]
for client in sequence: for client in sequence:
k = None
if type(client)==TupleType and len(client)==2: if type(client)==TupleType and len(client)==2:
if isort: k=client[0] if isort: k=client[0]
v=client[1] v=client[1]
...@@ -716,30 +722,43 @@ class InClass: ...@@ -716,30 +722,43 @@ class InClass:
v=client v=client
if sort: if sort:
if mapping: k=v[sort] if multsort: # More than one sort key.
else: k=getattr(v, sort) k = []
if not basic_type(k): for sk in sortfields:
try: k=k() try:
except: pass if mapping: akey = v[sk]
else: akey = getattr(v, sk)
except AttributeError, KeyError: akey = None
if not basic_type(akey):
try: akey = akey()
except: pass
k.append(akey)
else: # One sort key.
try:
if mapping: k = v[sort]
else: k = getattr(v, sort)
except AttributeError, KeyError: k = None
if not basic_type(k):
try: k = k()
except: pass
s.append((k,client)) s.append((k,client))
s.sort() s.sort()
sequence=[] sequence=[]
for k, client in s: sequence.append(client) for k, client in s:
sequence.append(client)
return sequence return sequence
def reverse_sequence(self, sequence): def reverse_sequence(self, sequence):
s=list(sequence) s=list(sequence)
s.reverse() s.reverse()
return s return s
basic_type={type(''): 1, type(0): 1, type(0.0): 1, type(()): 1, type([]): 1 basic_type={type(''): 1, type(0): 1, type(0.0): 1, type(()): 1, type([]): 1,
}.has_key type(None) : 1 }.has_key
def int_param(params,md,name,default=0, st=type('')): def int_param(params,md,name,default=0, st=type('')):
try: v=params[name] try: v=params[name]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment