From: richard Date: Sun, 29 Jul 2001 05:36:14 +0000 (+0000) Subject: Cleanup of the link label generation. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=6387f5e2319600eac6bc28f6f5609a842f45a932;p=roundup.git Cleanup of the link label generation. git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@129 57a73879-2fb5-44c3-a270-3262357dd7e2 --- diff --git a/roundup/htmltemplate.py b/roundup/htmltemplate.py index f39a72b..b7edbf4 100644 --- a/roundup/htmltemplate.py +++ b/roundup/htmltemplate.py @@ -1,4 +1,4 @@ -# $Id: htmltemplate.py,v 1.6 2001-07-29 04:06:42 richard Exp $ +# $Id: htmltemplate.py,v 1.7 2001-07-29 05:36:14 richard Exp $ import os, re, StringIO, urllib, cgi, errno @@ -41,32 +41,12 @@ class Plain(Base): value = str(value) elif propclass.isLinkType: linkcl = self.db.classes[propclass.classname] - k = linkcl.getkey() - # if the linked-to class doesn't have a key property, then try - # 'name', then 'title' and then just use a random one. - if not k: - linkprops = linkcl.getprops() - if linkprops.has_key('name'): - k = 'name' - elif linkprops.has_key('title'): - k = 'title' - else: - k = linkprops.keys()[0] + k = linkcl.labelprop() if value: value = str(linkcl.get(value, k)) else: value = '[unselected]' elif propclass.isMultilinkType: linkcl = self.db.classes[propclass.classname] - k = linkcl.getkey() - # if the linked-to class doesn't have a key property, then try - # 'name', then 'title' and then just use a random one. - if not k: - linkprops = linkcl.getprops() - if linkprops.has_key('name'): - k = 'name' - elif linkprops.has_key('title'): - k = 'title' - else: - k = linkprops.keys()[0] + k = linkcl.labelprop() value = ', '.join([linkcl.get(i, k) for i in value]) else: s = 'Plain: bad propclass "%s"'%propclass @@ -98,17 +78,7 @@ class Field(Base): elif propclass.isLinkType: linkcl = self.db.classes[propclass.classname] l = [''%(property, height)] - k = linkcl.getkey() - # if the linked-to class doesn't have a key property, then try - # 'name', then 'title' and then just use a random one. - if not k: - linkprops = linkcl.getprops() - if linkprops.has_key('name'): - k = 'name' - elif linkprops.has_key('title'): - k = 'title' - else: - k = linkprops.keys()[0] + k = linkcl.labelprop() for optionid in list: option = linkcl.get(optionid, k) s = '' @@ -171,17 +131,7 @@ class Menu(Base): if propclass.isLinkType: linkcl = self.db.classes[propclass.classname] l = [''%(property, height)] - k = linkcl.getkey() - # if the linked-to class doesn't have a key property, then try - # 'name', then 'title' and then just use a random one. - if not k: - linkprops = linkcl.getprops() - if linkprops.has_key('name'): - k = 'name' - elif linkprops.has_key('title'): - k = 'title' - else: - k = linkprops.keys()[0] + k = linkcl.labelprop() for optionid in list: option = linkcl.get(optionid, k) s = '' @@ -241,32 +181,12 @@ class Link(Base): if value is None: return '[not assigned]' linkcl = self.db.classes[propclass.classname] - k = linkcl.getkey() - # if the linked-to class doesn't have a key property, then try - # 'name', then 'title' and then just use a random one. - if not k: - linkprops = linkcl.getprops() - if linkprops.has_key('name'): - k = 'name' - elif linkprops.has_key('title'): - k = 'title' - else: - k = linkprops.keys()[0] + k = linkcl.labelprop() linkvalue = linkcl.get(value, k) return '%s'%(linkcl, value, linkvalue) if propclass.isMultilinkType: linkcl = self.db.classes[propclass.classname] - k = linkcl.getkey() - # if the linked-to class doesn't have a key property, then try - # 'name', then 'title' and then just use a random one. - if not k: - linkprops = linkcl.getprops() - if linkprops.has_key('name'): - k = 'name' - elif linkprops.has_key('title'): - k = 'title' - else: - k = linkprops.keys()[0] + k = linkcl.labelprop() l = [] for value in value: linkvalue = linkcl.get(value, k) @@ -350,17 +270,7 @@ class Checklist(Base): if propclass.isLinkType or propclass.isMultilinkType: linkcl = self.db.classes[propclass.classname] l = [] - k = linkcl.getkey() - # if the linked-to class doesn't have a key property, then try - # 'name', then 'title' and then just use a random one. - if not k: - linkprops = linkcl.getprops() - if linkprops.has_key('name'): - k = 'name' - elif linkprops.has_key('title'): - k = 'title' - else: - k = linkprops.keys()[0] + k = linkcl.labelprop() for optionid in linkcl.list(): option = linkcl.get(optionid, k) if optionid in value: @@ -797,6 +707,9 @@ def newitem(client, templates, db, classname, form, replace=re.compile( # # $Log: not supported by cvs2svn $ +# Revision 1.6 2001/07/29 04:06:42 richard +# Fixed problem in link display when Link value is None. +# # Revision 1.5 2001/07/28 08:17:09 richard # fixed use of stylesheet # diff --git a/roundup/hyperdb.py b/roundup/hyperdb.py index 4c13318..2a09c3c 100644 --- a/roundup/hyperdb.py +++ b/roundup/hyperdb.py @@ -1,4 +1,4 @@ -# $Id: hyperdb.py,v 1.5 2001-07-29 04:05:37 richard Exp $ +# $Id: hyperdb.py,v 1.6 2001-07-29 05:36:14 richard Exp $ # standard python modules import cPickle, re, string @@ -387,6 +387,28 @@ class Class: """Return the name of the key property for this class or None.""" return self.key + def labelprop(self, nodeid): + ''' Return the property name for a label for the given node. + + This method attempts to generate a consistent label for the node. + It tries the following in order: + 1. key property + 2. "name" property + 3. "title" property + 4. first property from the sorted property name list + ''' + k = self.getkey() + if k: + return k + props = self.getprops() + if props.has_key('name'): + return 'name' + elif props.has_key('title'): + return 'title' + props = props.keys() + props.sort() + return props[0] + # TODO: set up a separate index db file for this? profile? def lookup(self, keyvalue): """Locate a particular node by its key property and return its id. @@ -767,6 +789,9 @@ def Choice(name, *options): # # $Log: not supported by cvs2svn $ +# Revision 1.5 2001/07/29 04:05:37 richard +# Added the fabricated property "id". +# # Revision 1.4 2001/07/27 06:25:35 richard # Fixed some of the exceptions so they're the right type. # Removed the str()-ification of node ids so we don't mask oopsy errors any