1515# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717#
18- # $Id: htmltemplate.py,v 1.92 2002-06-11 04:57:04 richard Exp $
18+ # $Id: htmltemplate.py,v 1.93 2002-06-27 12:05:25 gmcm Exp $
1919
2020__doc__ = """
2121Template engine.
@@ -106,14 +106,14 @@ def do_plain(self, property, escape=0, lookup=1):
106106 if value :
107107 if lookup :
108108 linkcl = self .db .classes [propclass .classname ]
109- k = linkcl .labelprop ()
109+ k = linkcl .labelprop (1 )
110110 value = linkcl .get (value , k )
111111 else :
112112 value = _ ('[unselected]' )
113113 elif isinstance (propclass , hyperdb .Multilink ):
114114 if lookup :
115115 linkcl = self .db .classes [propclass .classname ]
116- k = linkcl .labelprop ()
116+ k = linkcl .labelprop (1 )
117117 labels = []
118118 for v in value :
119119 labels .append (linkcl .get (v , k ))
@@ -205,7 +205,7 @@ def do_field(self, property, size=None, showid=0):
205205 options .sort (sortfunc )
206206 # TODO: make this a field display, not a menu one!
207207 l = ['<select name="%s">' % property ]
208- k = linkcl .labelprop ()
208+ k = linkcl .labelprop (1 )
209209 if value is None :
210210 s = 'selected '
211211 else :
@@ -233,7 +233,7 @@ def do_field(self, property, size=None, showid=0):
233233 value .sort (sortfunc )
234234 # map the id to the label property
235235 if not showid :
236- k = linkcl .labelprop ()
236+ k = linkcl .labelprop (1 )
237237 value = [linkcl .get (v , k ) for v in value ]
238238 value = cgi .escape (',' .join (value ))
239239 s = '<input name="%s" size="%s" value="%s">' % (property , size , value )
@@ -293,7 +293,7 @@ def do_menu(self, property, size=None, height=None, showid=0,
293293 options .sort (sortfunc )
294294 height = height or min (len (options ), 7 )
295295 l = ['<select multiple name="%s" size="%s">' % (property , height )]
296- k = linkcl .labelprop ()
296+ k = linkcl .labelprop (1 )
297297 for optionid in options :
298298 option = linkcl .get (optionid , k )
299299 s = ''
@@ -321,7 +321,7 @@ def do_menu(self, property, size=None, height=None, showid=0,
321321 value = value [0 ]
322322 linkcl = self .db .classes [propclass .classname ]
323323 l = ['<select name="%s">' % property ]
324- k = linkcl .labelprop ()
324+ k = linkcl .labelprop (1 )
325325 s = ''
326326 if value is None :
327327 s = 'selected '
@@ -373,7 +373,7 @@ def do_link(self, property=None, is_download=0, showid=0):
373373 if isinstance (propclass , hyperdb .Link ):
374374 linkname = propclass .classname
375375 linkcl = self .db .classes [linkname ]
376- k = linkcl .labelprop ()
376+ k = linkcl .labelprop (1 )
377377 linkvalue = cgi .escape (str (linkcl .get (value , k )))
378378 if showid :
379379 label = value
@@ -390,7 +390,7 @@ def do_link(self, property=None, is_download=0, showid=0):
390390 if isinstance (propclass , hyperdb .Multilink ):
391391 linkname = propclass .classname
392392 linkcl = self .db .classes [linkname ]
393- k = linkcl .labelprop ()
393+ k = linkcl .labelprop (1 )
394394 l = []
395395 for value in value :
396396 linkvalue = cgi .escape (str (linkcl .get (value , k )))
@@ -493,7 +493,7 @@ def do_checklist(self, property, **args):
493493 # so we can map to the linked node's "lable" property
494494 linkcl = self .db .classes [propclass .classname ]
495495 l = []
496- k = linkcl .labelprop ()
496+ k = linkcl .labelprop (1 )
497497 for optionid in linkcl .list ():
498498 option = cgi .escape (str (linkcl .get (optionid , k )))
499499 if optionid in value or option in value :
@@ -616,7 +616,9 @@ def do_history(self, direction='descending'):
616616 labelprop = None
617617 comments [classname ] = _ ('''The linked class
618618 %(classname)s no longer exists''' )% locals ()
619- labelprop = linkcl .labelprop ()
619+ labelprop = linkcl .labelprop (1 )
620+ hrefable = os .path .exists (
621+ os .path .join (self .templates , classname + '.item' ))
620622
621623 if isinstance (prop , hyperdb .Multilink ) and \
622624 len (args [k ]) > 0 :
@@ -635,8 +637,11 @@ def do_history(self, direction='descending'):
635637 exists</strike>''' )
636638 ml .append ('<strike>%s</strike>' % label )
637639 else :
638- ml .append ('<a href="%s%s">%s</a>' % (
639- classname , linkid , label ))
640+ if hrefable :
641+ ml .append ('<a href="%s%s">%s</a>' % (
642+ classname , linkid , label ))
643+ else :
644+ ml .append (label )
640645 cell .append ('%s:\n %s' % (k , ',\n ' .join (ml )))
641646 elif isinstance (prop , hyperdb .Link ) and args [k ]:
642647 label = classname + args [k ]
@@ -654,8 +659,11 @@ def do_history(self, direction='descending'):
654659 # "flag" this is done .... euwww
655660 label = None
656661 if label is not None :
657- cell .append ('%s: <a href="%s%s">%s</a>\n ' % (k ,
658- classname , args [k ], label ))
662+ if hrefable :
663+ cell .append ('%s: <a href="%s%s">%s</a>\n ' % (k ,
664+ classname , args [k ], label ))
665+ else :
666+ cell .append ('%s: %s' % (k ,label ))
659667
660668 elif isinstance (prop , hyperdb .Date ) and args [k ]:
661669 d = date .Date (args [k ])
@@ -665,6 +673,9 @@ def do_history(self, direction='descending'):
665673 d = date .Interval (args [k ])
666674 cell .append ('%s: %s' % (k , str (d )))
667675
676+ elif isinstance (prop , hyperdb .String ) and args [k ]:
677+ cell .append ('%s: %s' % (k , cgi .escape (args [k ])))
678+
668679 elif not args [k ]:
669680 cell .append ('%s: (no value)\n ' % k )
670681
@@ -733,14 +744,16 @@ def __init__(self, globals, locals, props):
733744 r'((<property\s+name="(?P<name>[^>]+)">(?P<text>.+?)</property>)|'
734745 r'(?P<display><display\s+call="(?P<command>[^"]+)">))' , re .I | re .S )
735746 def go (self , text ):
736- return self .replace .sub (self , text )
747+ newtext = self .replace .sub (self , text )
748+ self .locals = self .globals = None
749+ return newtext
737750
738751 def __call__ (self , m , search_text = None , filter = None , columns = None ,
739752 sort = None , group = None ):
740753 if m .group ('name' ):
741754 if m .group ('name' ) in self .props :
742755 text = m .group ('text' )
743- replace = IndexTemplateReplace (self .globals , {}, self .props )
756+ replace = self . __class__ (self .globals , {}, self .props )
744757 return replace .go (text )
745758 else :
746759 return ''
@@ -768,6 +781,7 @@ def __init__(self, client, templates, classname):
768781 def render (self , filterspec = {}, search_text = '' , filter = [], columns = [],
769782 sort = [], group = [], show_display_form = 1 , nodeids = None ,
770783 show_customization = 1 , show_nodes = 1 ):
784+
771785 self .filterspec = filterspec
772786
773787 w = self .client .write
@@ -907,6 +921,8 @@ def render(self, filterspec={}, search_text='', filter=[], columns=[],
907921 ',' .join (sort ))
908922 w ('</form>\n ' )
909923
924+ self .db = self .cl = self .properties = None
925+
910926 def node_matches (self , match , colspan ):
911927 ''' display the files and messages for a node that matched a
912928 full text search
@@ -917,7 +933,7 @@ def node_matches(self, match, colspan):
917933 file_links = []
918934 if match .has_key ('messages' ):
919935 for msgid in match ['messages' ]:
920- k = self .db .msg .labelprop ()
936+ k = self .db .msg .labelprop (1 )
921937 lab = self .db .msg .get (msgid , k )
922938 msgpath = 'msg%s' % msgid
923939 message_links .append ('<a href="%(msgpath)s">%(lab)s</a>'
@@ -1105,7 +1121,9 @@ def __init__(self, globals, locals, cl, nodeid):
11051121 r'((<property\s+name="(?P<name>[^>]+)">(?P<text>.+?)</property>)|'
11061122 r'(?P<display><display\s+call="(?P<command>[^"]+)">))' , re .I | re .S )
11071123 def go (self , text ):
1108- return self .replace .sub (self , text )
1124+ newtext = self .replace .sub (self , text )
1125+ self .globals = self .locals = self .cl = None
1126+ return newtext
11091127
11101128 def __call__ (self , m , filter = None , columns = None , sort = None , group = None ):
11111129 if m .group ('name' ):
@@ -1153,6 +1171,7 @@ def render(self, nodeid):
11531171 replace = ItemTemplateReplace (self .globals , locals (), self .cl , nodeid )
11541172 w (replace .go (s ))
11551173 w ('</form>' )
1174+ self .cl = self .db = self .properties = None
11561175
11571176
11581177class NewItemTemplate (TemplateFunctions ):
@@ -1188,9 +1207,13 @@ def render(self, form):
11881207 replace = ItemTemplateReplace (self .globals , locals (), None , None )
11891208 w (replace .go (s ))
11901209 w ('</form>' )
1210+ self .cl = self .db = None
11911211
11921212#
11931213# $Log: not supported by cvs2svn $
1214+ # Revision 1.92 2002/06/11 04:57:04 richard
1215+ # Added optional additional property to display in a Multilink form menu.
1216+ #
11941217# Revision 1.91 2002/05/31 00:08:02 richard
11951218# can now just display a link/multilink id - useful for stylesheet stuff
11961219#
0 commit comments