1- # $Id: htmltemplate.py,v 1.6 2001-07-29 04:06:42 richard Exp $
1+ # $Id: htmltemplate.py,v 1.7 2001-07-29 05:36:14 richard Exp $
22
33import os , re , StringIO , urllib , cgi , errno
44
@@ -41,32 +41,12 @@ def __call__(self, property):
4141 value = str (value )
4242 elif propclass .isLinkType :
4343 linkcl = self .db .classes [propclass .classname ]
44- k = linkcl .getkey ()
45- # if the linked-to class doesn't have a key property, then try
46- # 'name', then 'title' and then just use a random one.
47- if not k :
48- linkprops = linkcl .getprops ()
49- if linkprops .has_key ('name' ):
50- k = 'name'
51- elif linkprops .has_key ('title' ):
52- k = 'title'
53- else :
54- k = linkprops .keys ()[0 ]
44+ k = linkcl .labelprop ()
5545 if value : value = str (linkcl .get (value , k ))
5646 else : value = '[unselected]'
5747 elif propclass .isMultilinkType :
5848 linkcl = self .db .classes [propclass .classname ]
59- k = linkcl .getkey ()
60- # if the linked-to class doesn't have a key property, then try
61- # 'name', then 'title' and then just use a random one.
62- if not k :
63- linkprops = linkcl .getprops ()
64- if linkprops .has_key ('name' ):
65- k = 'name'
66- elif linkprops .has_key ('title' ):
67- k = 'title'
68- else :
69- k = linkprops .keys ()[0 ]
49+ k = linkcl .labelprop ()
7050 value = ', ' .join ([linkcl .get (i , k ) for i in value ])
7151 else :
7252 s = 'Plain: bad propclass "%s"' % propclass
@@ -98,17 +78,7 @@ def __call__(self, property, size=None, height=None, showid=0):
9878 elif propclass .isLinkType :
9979 linkcl = self .db .classes [propclass .classname ]
10080 l = ['<select name="%s">' % property ]
101- k = linkcl .getkey ()
102- # if the linked-to class doesn't have a key property, then try
103- # 'name', then 'title' and then just use a random one.
104- if not k :
105- linkprops = linkcl .getprops ()
106- if linkprops .has_key ('name' ):
107- k = 'name'
108- elif linkprops .has_key ('title' ):
109- k = 'title'
110- else :
111- k = linkprops .keys ()[0 ]
81+ k = linkcl .labelprop ()
11282 for optionid in linkcl .list ():
11383 option = linkcl .get (optionid , k )
11484 s = ''
@@ -128,17 +98,7 @@ def __call__(self, property, size=None, height=None, showid=0):
12898 list = linkcl .list ()
12999 height = height or min (len (list ), 7 )
130100 l = ['<select multiple name="%s" size="%s">' % (property , height )]
131- k = linkcl .getkey ()
132- # if the linked-to class doesn't have a key property, then try
133- # 'name', then 'title' and then just use a random one.
134- if not k :
135- linkprops = linkcl .getprops ()
136- if linkprops .has_key ('name' ):
137- k = 'name'
138- elif linkprops .has_key ('title' ):
139- k = 'title'
140- else :
141- k = linkprops .keys ()[0 ]
101+ k = linkcl .labelprop ()
142102 for optionid in list :
143103 option = linkcl .get (optionid , k )
144104 s = ''
@@ -171,17 +131,7 @@ def __call__(self, property, size=None, height=None, showid=0):
171131 if propclass .isLinkType :
172132 linkcl = self .db .classes [propclass .classname ]
173133 l = ['<select name="%s">' % property ]
174- k = linkcl .getkey ()
175- # if the linked-to class doesn't have a key property, then try
176- # 'name', then 'title' and then just use a random one.
177- if not k :
178- linkprops = linkcl .getprops ()
179- if linkprops .has_key ('name' ):
180- k = 'name'
181- elif linkprops .has_key ('title' ):
182- k = 'title'
183- else :
184- k = linkprops .keys ()[0 ]
134+ k = linkcl .labelprop ()
185135 for optionid in linkcl .list ():
186136 option = linkcl .get (optionid , k )
187137 s = ''
@@ -195,17 +145,7 @@ def __call__(self, property, size=None, height=None, showid=0):
195145 list = linkcl .list ()
196146 height = height or min (len (list ), 7 )
197147 l = ['<select multiple name="%s" size="%s">' % (property , height )]
198- k = linkcl .getkey ()
199- # if the linked-to class doesn't have a key property, then try
200- # 'name', then 'title' and then just use a random one.
201- if not k :
202- linkprops = linkcl .getprops ()
203- if linkprops .has_key ('name' ):
204- k = 'name'
205- elif linkprops .has_key ('title' ):
206- k = 'title'
207- else :
208- k = linkprops .keys ()[0 ]
148+ k = linkcl .labelprop ()
209149 for optionid in list :
210150 option = linkcl .get (optionid , k )
211151 s = ''
@@ -241,32 +181,12 @@ def __call__(self, property=None, **args):
241181 if value is None :
242182 return '[not assigned]'
243183 linkcl = self .db .classes [propclass .classname ]
244- k = linkcl .getkey ()
245- # if the linked-to class doesn't have a key property, then try
246- # 'name', then 'title' and then just use a random one.
247- if not k :
248- linkprops = linkcl .getprops ()
249- if linkprops .has_key ('name' ):
250- k = 'name'
251- elif linkprops .has_key ('title' ):
252- k = 'title'
253- else :
254- k = linkprops .keys ()[0 ]
184+ k = linkcl .labelprop ()
255185 linkvalue = linkcl .get (value , k )
256186 return '<a href="%s%s">%s</a>' % (linkcl , value , linkvalue )
257187 if propclass .isMultilinkType :
258188 linkcl = self .db .classes [propclass .classname ]
259- k = linkcl .getkey ()
260- # if the linked-to class doesn't have a key property, then try
261- # 'name', then 'title' and then just use a random one.
262- if not k :
263- linkprops = linkcl .getprops ()
264- if linkprops .has_key ('name' ):
265- k = 'name'
266- elif linkprops .has_key ('title' ):
267- k = 'title'
268- else :
269- k = linkprops .keys ()[0 ]
189+ k = linkcl .labelprop ()
270190 l = []
271191 for value in value :
272192 linkvalue = linkcl .get (value , k )
@@ -350,17 +270,7 @@ def __call__(self, property, **args):
350270 if propclass .isLinkType or propclass .isMultilinkType :
351271 linkcl = self .db .classes [propclass .classname ]
352272 l = []
353- k = linkcl .getkey ()
354- # if the linked-to class doesn't have a key property, then try
355- # 'name', then 'title' and then just use a random one.
356- if not k :
357- linkprops = linkcl .getprops ()
358- if linkprops .has_key ('name' ):
359- k = 'name'
360- elif linkprops .has_key ('title' ):
361- k = 'title'
362- else :
363- k = linkprops .keys ()[0 ]
273+ k = linkcl .labelprop ()
364274 for optionid in linkcl .list ():
365275 option = linkcl .get (optionid , k )
366276 if optionid in value :
@@ -797,6 +707,9 @@ def newitem(client, templates, db, classname, form, replace=re.compile(
797707
798708#
799709# $Log: not supported by cvs2svn $
710+ # Revision 1.6 2001/07/29 04:06:42 richard
711+ # Fixed problem in link display when Link value is None.
712+ #
800713# Revision 1.5 2001/07/28 08:17:09 richard
801714# fixed use of stylesheet
802715#
0 commit comments