Mercurial > p > roundup > code
comparison roundup/cgi/templating.py @ 1202:01a143f9382e
*** empty log message ***
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Tue, 24 Sep 2002 05:50:26 +0000 |
| parents | 0f1224acffbb |
| children | b862bbf2067a |
comparison
equal
deleted
inserted
replaced
| 1201:0f1224acffbb | 1202:01a143f9382e |
|---|---|
| 285 if not isinstance(prop, klass): | 285 if not isinstance(prop, klass): |
| 286 continue | 286 continue |
| 287 if form.has_key(item): | 287 if form.has_key(item): |
| 288 if isinstance(prop, hyperdb.Multilink): | 288 if isinstance(prop, hyperdb.Multilink): |
| 289 value = lookupIds(self._db, prop, | 289 value = lookupIds(self._db, prop, |
| 290 handleListCGIValue(None, form[item])) | 290 handleListCGIValue(form[item])) |
| 291 elif isinstance(prop, hyperdb.Link): | 291 elif isinstance(prop, hyperdb.Link): |
| 292 value = form[item].value.strip() | 292 value = form[item].value.strip() |
| 293 if value: | 293 if value: |
| 294 value = lookupIds(self._db, prop, [value])[0] | 294 value = lookupIds(self._db, prop, [value])[0] |
| 295 else: | 295 else: |
| 1172 sort_on = linkcl.labelprop() | 1172 sort_on = linkcl.labelprop() |
| 1173 def sortfunc(a, b, linkcl=linkcl, sort_on=sort_on): | 1173 def sortfunc(a, b, linkcl=linkcl, sort_on=sort_on): |
| 1174 return cmp(linkcl.get(a, sort_on), linkcl.get(b, sort_on)) | 1174 return cmp(linkcl.get(a, sort_on), linkcl.get(b, sort_on)) |
| 1175 return sortfunc | 1175 return sortfunc |
| 1176 | 1176 |
| 1177 def handleListCGIValue(klass, value, num_re=re.compile('\d+')): | 1177 def handleListCGIValue(value): |
| 1178 ''' Value is either a single item or a list of items. Each item has a | 1178 ''' Value is either a single item or a list of items. Each item has a |
| 1179 .value that we're actually interested in. | 1179 .value that we're actually interested in. |
| 1180 ''' | 1180 ''' |
| 1181 if isinstance(value, type([])): | 1181 if isinstance(value, type([])): |
| 1182 l = [value.value for value in value] | 1182 return [value.value for value in value] |
| 1183 else: | 1183 else: |
| 1184 value = value.value.strip() | 1184 value = value.value.strip() |
| 1185 if not value: | 1185 if not value: |
| 1186 return [] | 1186 return [] |
| 1187 l = value.split(',') | 1187 return 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 | |
| 1201 | 1188 |
| 1202 class ShowDict: | 1189 class ShowDict: |
| 1203 ''' A convenience access to the :columns index parameters | 1190 ''' A convenience access to the :columns index parameters |
| 1204 ''' | 1191 ''' |
| 1205 def __init__(self, columns): | 1192 def __init__(self, columns): |
| 1249 ''' Set attributes based on self.form | 1236 ''' Set attributes based on self.form |
| 1250 ''' | 1237 ''' |
| 1251 # extract the index display information from the form | 1238 # extract the index display information from the form |
| 1252 self.columns = [] | 1239 self.columns = [] |
| 1253 if self.form.has_key(':columns'): | 1240 if self.form.has_key(':columns'): |
| 1254 self.columns = handleListCGIValue(None, self.form[':columns']) | 1241 self.columns = handleListCGIValue(self.form[':columns']) |
| 1255 self.show = ShowDict(self.columns) | 1242 self.show = ShowDict(self.columns) |
| 1256 | 1243 |
| 1257 # sorting | 1244 # sorting |
| 1258 self.sort = (None, None) | 1245 self.sort = (None, None) |
| 1259 if self.form.has_key(':sort'): | 1246 if self.form.has_key(':sort'): |
| 1277 self.group = ('-', self.group[1]) | 1264 self.group = ('-', self.group[1]) |
| 1278 | 1265 |
| 1279 # filtering | 1266 # filtering |
| 1280 self.filter = [] | 1267 self.filter = [] |
| 1281 if self.form.has_key(':filter'): | 1268 if self.form.has_key(':filter'): |
| 1282 self.filter = handleListCGIValue(None, self.form[':filter']) | 1269 self.filter = handleListCGIValue(self.form[':filter']) |
| 1283 self.filterspec = {} | 1270 self.filterspec = {} |
| 1284 db = self.client.db | 1271 db = self.client.db |
| 1285 if self.classname is not None: | 1272 if self.classname is not None: |
| 1286 props = db.getclass(self.classname).getprops() | 1273 props = db.getclass(self.classname).getprops() |
| 1287 for name in self.filter: | 1274 for name in self.filter: |
| 1288 if self.form.has_key(name): | 1275 if self.form.has_key(name): |
| 1289 prop = props[name] | 1276 prop = props[name] |
| 1290 fv = self.form[name] | 1277 fv = self.form[name] |
| 1291 if (isinstance(prop, hyperdb.Link) or | 1278 if (isinstance(prop, hyperdb.Link) or |
| 1292 isinstance(prop, hyperdb.Multilink)): | 1279 isinstance(prop, hyperdb.Multilink)): |
| 1293 cl = db.getclass(prop.classname) | 1280 self.filterspec[name] = lookupIds(db, prop, |
| 1294 self.filterspec[name] = handleListCGIValue(cl, fv) | 1281 handleListCGIValue(fv)) |
| 1295 else: | 1282 else: |
| 1296 self.filterspec[name] = fv.value | 1283 self.filterspec[name] = fv.value |
| 1297 | 1284 |
| 1298 # full-text search argument | 1285 # full-text search argument |
| 1299 self.search_text = None | 1286 self.search_text = None |
| 1355 def __str__(self): | 1342 def __str__(self): |
| 1356 d = {} | 1343 d = {} |
| 1357 d.update(self.__dict__) | 1344 d.update(self.__dict__) |
| 1358 f = '' | 1345 f = '' |
| 1359 for k in self.form.keys(): | 1346 for k in self.form.keys(): |
| 1360 f += '\n %r=%r'%(k,handleListCGIValue(None, self.form[k])) | 1347 f += '\n %r=%r'%(k,handleListCGIValue(self.form[k])) |
| 1361 d['form'] = f | 1348 d['form'] = f |
| 1362 e = '' | 1349 e = '' |
| 1363 for k,v in self.env.items(): | 1350 for k,v in self.env.items(): |
| 1364 e += '\n %r=%r'%(k, v) | 1351 e += '\n %r=%r'%(k, v) |
| 1365 d['env'] = e | 1352 d['env'] = e |
