index 3e34c043a1d916a98603cc85c7e17a48e3325e6a..f1b78b448790ed8da5cf57b7dc7e219f38a89e1b 100644 (file)
l = self._client.db.classes.keys()
l.sort()
return [HTMLClass(self._client, cn) for cn in l]
-
+
+def lookupIds(db, prop, ids, num_re=re.compile('-?\d+')):
+ cl = db.getclass(prop.classname)
+ l = []
+ for entry in ids:
+ if num_re.match(entry):
+ l.append(entry)
+ else:
+ l.append(cl.lookup(entry))
+ return l
+
class HTMLClass:
''' Accesses through a class (either through *class* or *db.<classname>*)
'''
prop = self._props[item]
# look up the correct HTMLProperty class
+ form = self._client.form
for klass, htmlklass in propclasses:
- if isinstance(prop, hyperdb.Multilink):
- value = []
+ if not isinstance(prop, klass):
+ continue
+ if form.has_key(item):
+ if isinstance(prop, hyperdb.Multilink):
+ value = lookupIds(self._db, prop,
+ handleListCGIValue(form[item]))
+ elif isinstance(prop, hyperdb.Link):
+ value = form[item].value.strip()
+ if value:
+ value = lookupIds(self._db, prop, [value])[0]
+ else:
+ value = None
+ else:
+ value = form[item].value.strip() or None
else:
- value = None
- if isinstance(prop, klass):
- return htmlklass(self._client, '', prop, item, value)
+ if isinstance(prop, hyperdb.Multilink):
+ value = []
+ else:
+ value = None
+ print (prop, value)
+ return htmlklass(self._client, '', prop, item, value)
# no good
raise KeyError, item
for x in self._klass.filter(None, filterspec, sort, group)]
return l
- def classhelp(self, properties, label='?', width='400', height='400'):
- '''pop up a javascript window with class help
+ def classhelp(self, properties=None, label='list', width='500',
+ height='400'):
+ ''' Pop up a javascript window with class help
- This generates a link to a popup window which displays the
- properties indicated by "properties" of the class named by
- "classname". The "properties" should be a comma-separated list
- (eg. 'id,name,description').
+ This generates a link to a popup window which displays the
+ properties indicated by "properties" of the class named by
+ "classname". The "properties" should be a comma-separated list
+ (eg. 'id,name,description'). Properties defaults to all the
+ properties of a class (excluding id, creator, created and
+ activity).
- You may optionally override the label displayed, the width and
- height. The popup window will be resizable and scrollable.
+ You may optionally override the label displayed, the width and
+ height. The popup window will be resizable and scrollable.
'''
+ if properties is None:
+ properties = self._klass.getprops(protected=0).keys()
+ properties.sort()
+ properties = ','.join(properties)
return '<a href="javascript:help_window(\'%s?:template=help&' \
':contentonly=1&properties=%s\', \'%s\', \'%s\')"><b>'\
'(%s)</b></a>'%(self.classname, properties, width, height, label)
if isinstance(value, type([])):
return [value.value for value in value]
else:
- return value.value.split(',')
+ value = value.value.strip()
+ if not value:
+ return []
+ return value.split(',')
class ShowDict:
''' A convenience access to the :columns index parameters