comparison roundup/hyperdb.py @ 123:51cce9671db0

Cleanup of the link label generation.
author Richard Jones <richard@users.sourceforge.net>
date Sun, 29 Jul 2001 05:36:14 +0000
parents a55c1301ba1f
children 0791d13baea7
comparison
equal deleted inserted replaced
122:828632ab0adf 123:51cce9671db0
1 # $Id: hyperdb.py,v 1.5 2001-07-29 04:05:37 richard Exp $ 1 # $Id: hyperdb.py,v 1.6 2001-07-29 05:36:14 richard Exp $
2 2
3 # standard python modules 3 # standard python modules
4 import cPickle, re, string 4 import cPickle, re, string
5 5
6 # roundup modules 6 # roundup modules
384 self.key = propname 384 self.key = propname
385 385
386 def getkey(self): 386 def getkey(self):
387 """Return the name of the key property for this class or None.""" 387 """Return the name of the key property for this class or None."""
388 return self.key 388 return self.key
389
390 def labelprop(self, nodeid):
391 ''' Return the property name for a label for the given node.
392
393 This method attempts to generate a consistent label for the node.
394 It tries the following in order:
395 1. key property
396 2. "name" property
397 3. "title" property
398 4. first property from the sorted property name list
399 '''
400 k = self.getkey()
401 if k:
402 return k
403 props = self.getprops()
404 if props.has_key('name'):
405 return 'name'
406 elif props.has_key('title'):
407 return 'title'
408 props = props.keys()
409 props.sort()
410 return props[0]
389 411
390 # TODO: set up a separate index db file for this? profile? 412 # TODO: set up a separate index db file for this? profile?
391 def lookup(self, keyvalue): 413 def lookup(self, keyvalue):
392 """Locate a particular node by its key property and return its id. 414 """Locate a particular node by its key property and return its id.
393 415
765 cl.create(name=option[i], order=i) 787 cl.create(name=option[i], order=i)
766 return hyperdb.Link(name) 788 return hyperdb.Link(name)
767 789
768 # 790 #
769 # $Log: not supported by cvs2svn $ 791 # $Log: not supported by cvs2svn $
792 # Revision 1.5 2001/07/29 04:05:37 richard
793 # Added the fabricated property "id".
794 #
770 # Revision 1.4 2001/07/27 06:25:35 richard 795 # Revision 1.4 2001/07/27 06:25:35 richard
771 # Fixed some of the exceptions so they're the right type. 796 # Fixed some of the exceptions so they're the right type.
772 # Removed the str()-ification of node ids so we don't mask oopsy errors any 797 # Removed the str()-ification of node ids so we don't mask oopsy errors any
773 # more. 798 # more.
774 # 799 #

Roundup Issue Tracker: http://roundup-tracker.org/