Skip to content

Commit 9441326

Browse files
author
Richard Jones
committed
Hrm - displaying links to classes that don't specify a key property.
I've got it defaulting to 'name', then 'title' and then a "random" property (first one returned by getprops().keys(). Needs to be moved onto the Class I think...
1 parent a70ccdc commit 9441326

File tree

1 file changed

+98
-2
lines changed

1 file changed

+98
-2
lines changed

roundup/htmltemplate.py

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: htmltemplate.py,v 1.2 2001-07-22 12:09:32 richard Exp $
1+
# $Id: htmltemplate.py,v 1.3 2001-07-25 03:39:47 richard Exp $
22

33
import os, re, StringIO, urllib, cgi
44

@@ -41,11 +41,32 @@ def __call__(self, property):
4141
value = str(value)
4242
elif propclass.isLinkType:
4343
linkcl = self.db.classes[propclass.classname]
44-
if value: value = str(linkcl.get(value, linkcl.getkey()))
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]
55+
if value: value = str(linkcl.get(value, k))
4556
else: value = '[unselected]'
4657
elif propclass.isMultilinkType:
4758
linkcl = self.db.classes[propclass.classname]
4859
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]
4970
value = ', '.join([linkcl.get(i, k) for i in value])
5071
else:
5172
s = 'Plain: bad propclass "%s"'%propclass
@@ -78,6 +99,16 @@ def __call__(self, property, size=None, height=None, showid=0):
7899
linkcl = self.db.classes[propclass.classname]
79100
l = ['<select name="%s">'%property]
80101
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]
81112
for optionid in linkcl.list():
82113
option = linkcl.get(optionid, k)
83114
s = ''
@@ -98,6 +129,16 @@ def __call__(self, property, size=None, height=None, showid=0):
98129
height = height or min(len(list), 7)
99130
l = ['<select multiple name="%s" size="%s">'%(property, height)]
100131
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]
101142
for optionid in list:
102143
option = linkcl.get(optionid, k)
103144
s = ''
@@ -131,6 +172,16 @@ def __call__(self, property, size=None, height=None, showid=0):
131172
linkcl = self.db.classes[propclass.classname]
132173
l = ['<select name="%s">'%property]
133174
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]
134185
for optionid in linkcl.list():
135186
option = linkcl.get(optionid, k)
136187
s = ''
@@ -145,6 +196,16 @@ def __call__(self, property, size=None, height=None, showid=0):
145196
height = height or min(len(list), 7)
146197
l = ['<select multiple name="%s" size="%s">'%(property, height)]
147198
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]
148209
for optionid in list:
149210
option = linkcl.get(optionid, k)
150211
s = ''
@@ -178,10 +239,32 @@ def __call__(self, property=None, **args):
178239
else: value = ''
179240
if propclass.isLinkType:
180241
linkcl = self.db.classes[propclass.classname]
242+
k = linkcl.getkey()
243+
# if the linked-to class doesn't have a key property, then try
244+
# 'name', then 'title' and then just use a random one.
245+
if not k:
246+
linkprops = linkcl.getprops()
247+
if linkprops.has_key('name'):
248+
k = 'name'
249+
elif linkprops.has_key('title'):
250+
k = 'title'
251+
else:
252+
k = linkprops.keys()[0]
181253
linkvalue = linkcl.get(value, k)
182254
return '<a href="%s%s">%s</a>'%(linkcl, value, linkvalue)
183255
if propclass.isMultilinkType:
184256
linkcl = self.db.classes[propclass.classname]
257+
k = linkcl.getkey()
258+
# if the linked-to class doesn't have a key property, then try
259+
# 'name', then 'title' and then just use a random one.
260+
if not k:
261+
linkprops = linkcl.getprops()
262+
if linkprops.has_key('name'):
263+
k = 'name'
264+
elif linkprops.has_key('title'):
265+
k = 'title'
266+
else:
267+
k = linkprops.keys()[0]
185268
l = []
186269
for value in value:
187270
linkvalue = linkcl.get(value, k)
@@ -266,6 +349,16 @@ def __call__(self, property, **args):
266349
linkcl = self.db.classes[propclass.classname]
267350
l = []
268351
k = linkcl.getkey()
352+
# if the linked-to class doesn't have a key property, then try
353+
# 'name', then 'title' and then just use a random one.
354+
if not k:
355+
linkprops = linkcl.getprops()
356+
if linkprops.has_key('name'):
357+
k = 'name'
358+
elif linkprops.has_key('title'):
359+
k = 'title'
360+
else:
361+
k = linkprops.keys()[0]
269362
for optionid in linkcl.list():
270363
option = linkcl.get(optionid, k)
271364
if optionid in value:
@@ -702,6 +795,9 @@ def newitem(client, templates, db, classname, form, replace=re.compile(
702795

703796
#
704797
# $Log: not supported by cvs2svn $
798+
# Revision 1.2 2001/07/22 12:09:32 richard
799+
# Final commit of Grande Splite
800+
#
705801
# Revision 1.1 2001/07/22 11:58:35 richard
706802
# More Grande Splite
707803
#

0 commit comments

Comments
 (0)