@@ -313,6 +313,20 @@ def __getattr__(self, attr):
313313 except KeyError :
314314 raise AttributeError , attr
315315
316+ def getItem (self , itemid , num_re = re .compile ('\d+' )):
317+ ''' Get an item of this class by its item id.
318+ '''
319+ # make sure we're looking at an itemid
320+ if not num_re .match (itemid ):
321+ itemid = self ._klass .lookup (itemid )
322+
323+ if self .classname == 'user' :
324+ klass = HTMLUser
325+ else :
326+ klass = HTMLItem
327+
328+ return klass (self ._client , self .classname , itemid )
329+
316330 def properties (self ):
317331 ''' Return HTMLProperty for all of this class' properties.
318332 '''
@@ -1160,17 +1174,30 @@ def sortfunc(a, b, linkcl=linkcl, sort_on=sort_on):
11601174 return cmp (linkcl .get (a , sort_on ), linkcl .get (b , sort_on ))
11611175 return sortfunc
11621176
1163- def handleListCGIValue (value ):
1177+ def handleListCGIValue (klass , value , num_re = re . compile ( '\d+' ) ):
11641178 ''' Value is either a single item or a list of items. Each item has a
11651179 .value that we're actually interested in.
11661180 '''
11671181 if isinstance (value , type ([])):
1168- return [value .value for value in value ]
1182+ l = [value .value for value in value ]
11691183 else :
11701184 value = value .value .strip ()
11711185 if not value :
11721186 return []
1173- return value .split (',' )
1187+ l = value .split (',' )
1188+
1189+ if klass is None :
1190+ return l
1191+
1192+ # otherwise, try to make sure the values are itemids of the given class
1193+ r = []
1194+ for itemid in l :
1195+ # make sure we're looking at an itemid
1196+ if not num_re .match (itemid ):
1197+ itemid = self ._klass .lookup (itemid )
1198+ else :
1199+ r .append (itemid )
1200+ return r
11741201
11751202class ShowDict :
11761203 ''' A convenience access to the :columns index parameters
@@ -1224,7 +1251,7 @@ def _post_init(self):
12241251 # extract the index display information from the form
12251252 self .columns = []
12261253 if self .form .has_key (':columns' ):
1227- self .columns = handleListCGIValue (self .form [':columns' ])
1254+ self .columns = handleListCGIValue (None , self .form [':columns' ])
12281255 self .show = ShowDict (self .columns )
12291256
12301257 # sorting
@@ -1254,15 +1281,17 @@ def _post_init(self):
12541281 if self .form .has_key (':filter' ):
12551282 self .filter = handleListCGIValue (self .form [':filter' ])
12561283 self .filterspec = {}
1284+ db = self .client .db
12571285 if self .classname is not None :
1258- props = self . client . db .getclass (self .classname ).getprops ()
1286+ props = db .getclass (self .classname ).getprops ()
12591287 for name in self .filter :
12601288 if self .form .has_key (name ):
12611289 prop = props [name ]
12621290 fv = self .form [name ]
12631291 if (isinstance (prop , hyperdb .Link ) or
12641292 isinstance (prop , hyperdb .Multilink )):
1265- self .filterspec [name ] = handleListCGIValue (fv )
1293+ cl = db .getclass (prop .classname )
1294+ self .filterspec [name ] = handleListCGIValue (cl , fv )
12661295 else :
12671296 self .filterspec [name ] = fv .value
12681297
0 commit comments