1515# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717#
18- # $Id: htmltemplate.py,v 1.49 2001-12-20 15:43:01 rochecompaan Exp $
18+ # $Id: htmltemplate.py,v 1.50 2002-01-05 02:35:10 richard Exp $
1919
2020__doc__ = """
2121Template engine.
2424import os , re , StringIO , urllib , cgi , errno
2525
2626import hyperdb , date , password
27+ from i18n import _
2728
2829# This imports the StructureText functionality for the do_stext function
2930# get it from http://dev.zope.org/Members/jim/StructuredTextWiki/NGReleases
@@ -52,7 +53,7 @@ def do_plain(self, property, escape=0):
5253 linked nodes (or the ids if the linked class has no key property)
5354 '''
5455 if not self .nodeid and self .form is None :
55- return '[Field: not called from item]'
56+ return _ ( '[Field: not called from item]' )
5657 propclass = self .properties [property ]
5758 if self .nodeid :
5859 # make sure the property is a valid one
@@ -76,7 +77,7 @@ def do_plain(self, property, escape=0):
7677 else : value = str (value )
7778 elif isinstance (propclass , hyperdb .Password ):
7879 if value is None : value = ''
79- else : value = '*encrypted*'
80+ else : value = _ ( '*encrypted*' )
8081 elif isinstance (propclass , hyperdb .Date ):
8182 value = str (value )
8283 elif isinstance (propclass , hyperdb .Interval ):
@@ -85,7 +86,7 @@ def do_plain(self, property, escape=0):
8586 linkcl = self .db .classes [propclass .classname ]
8687 k = linkcl .labelprop ()
8788 if value : value = str (linkcl .get (value , k ))
88- else : value = '[unselected]'
89+ else : value = _ ( '[unselected]' )
8990 elif isinstance (propclass , hyperdb .Multilink ):
9091 linkcl = self .db .classes [propclass .classname ]
9192 k = linkcl .labelprop ()
@@ -158,7 +159,7 @@ def sortfunc(a, b, cl=linkcl):
158159 s = 'selected '
159160 else :
160161 s = ''
161- l .append ('<option %svalue="-1">- no selection -</option>' % s )
162+ l .append (_ ( '<option %svalue="-1">- no selection -</option>' ) % s )
162163 options = linkcl .list ()
163164 options .sort (sortfunc )
164165 for optionid in options :
@@ -197,7 +198,7 @@ def sortfunc(a, b, cl=linkcl):
197198 size , ',' .join (input_value )))
198199 s = "<br>\n " .join (l )
199200 else :
200- s = 'Plain: bad propclass "%s"' % propclass
201+ s = _ ( 'Plain: bad propclass "%(propclass) s"' ) % locals ()
201202 return s
202203
203204 def do_menu (self , property , size = None , height = None , showid = 0 ):
@@ -217,7 +218,7 @@ def do_menu(self, property, size=None, height=None, showid=0):
217218 s = ''
218219 if value is None :
219220 s = 'selected '
220- l .append ('<option %svalue="-1">- no selection -</option>' % s )
221+ l .append (_ ( '<option %svalue="-1">- no selection -</option>' ) % s )
221222 for optionid in linkcl .list ():
222223 option = linkcl .get (optionid , k )
223224 s = ''
@@ -246,7 +247,7 @@ def do_menu(self, property, size=None, height=None, showid=0):
246247 l .append ('<option %svalue="%s">%s</option>' % (s , optionid , option ))
247248 l .append ('</select>' )
248249 return '\n ' .join (l )
249- return '[Menu: not a link]'
250+ return _ ( '[Menu: not a link]' )
250251
251252 #XXX deviates from spec
252253 def do_link (self , property = None , is_download = 0 ):
@@ -260,7 +261,7 @@ def do_link(self, property=None, is_download=0):
260261 downloaded file name is correct.
261262 '''
262263 if not self .nodeid and self .form is None :
263- return '[Link: not called from item]'
264+ return _ ( '[Link: not called from item]' )
264265 propclass = self .properties [property ]
265266 if self .nodeid :
266267 value = self .cl .get (self .nodeid , property )
@@ -283,7 +284,8 @@ def do_link(self, property=None, is_download=0):
283284 linkname = propclass .classname
284285 linkcl = self .db .classes [linkname ]
285286 k = linkcl .labelprop ()
286- if not value : return '[no %s]' % property .capitalize ()
287+ if not value :
288+ return _ ('[no %(propname)s]' )% {'propname' : property .capitalize ()}
287289 l = []
288290 for value in value :
289291 linkvalue = linkcl .get (value , k )
@@ -294,8 +296,8 @@ def do_link(self, property=None, is_download=0):
294296 l .append ('<a href="%s%s">%s</a>' % (linkname , value ,
295297 linkvalue ))
296298 return ', ' .join (l )
297- if isinstance (propclass , hyperdb .String ):
298- if value == '' : value = ' [no %s]'% property .capitalize ()
299+ if isinstance (propclass , hyperdb .String ) and value == '' :
300+ return _ ( ' [no %(propname) s]') % { 'propname' : property .capitalize ()}
299301 if is_download :
300302 return '<a href="%s%s/%s">%s</a>' % (self .classname , self .nodeid ,
301303 value , value )
@@ -307,12 +309,12 @@ def do_count(self, property, **args):
307309 the list
308310 '''
309311 if not self .nodeid :
310- return '[Count: not called from item]'
312+ return _ ( '[Count: not called from item]' )
311313 propclass = self .properties [property ]
312314 value = self .cl .get (self .nodeid , property )
313315 if isinstance (propclass , hyperdb .Multilink ):
314316 return str (len (value ))
315- return '[Count: not a Multilink]'
317+ return _ ( '[Count: not a Multilink]' )
316318
317319 # XXX pretty is definitely new ;)
318320 def do_reldate (self , property , pretty = 0 ):
@@ -322,18 +324,18 @@ def do_reldate(self, property, pretty=0):
322324 with the 'pretty' flag, make it pretty
323325 '''
324326 if not self .nodeid and self .form is None :
325- return '[Reldate: not called from item]'
327+ return _ ( '[Reldate: not called from item]' )
326328 propclass = self .properties [property ]
327329 if isinstance (not propclass , hyperdb .Date ):
328- return '[Reldate: not a Date]'
330+ return _ ( '[Reldate: not a Date]' )
329331 if self .nodeid :
330332 value = self .cl .get (self .nodeid , property )
331333 else :
332334 value = date .Date ('.' )
333335 interval = value - date .Date ('.' )
334336 if pretty :
335337 if not self .nodeid :
336- return 'now'
338+ return _ ( 'now' )
337339 pretty = interval .pretty ()
338340 if pretty is None :
339341 pretty = value .pretty ()
@@ -345,7 +347,7 @@ def do_download(self, property, **args):
345347 allow you to download files
346348 '''
347349 if not self .nodeid :
348- return '[Download: not called from item]'
350+ return _ ( '[Download: not called from item]' )
349351 propclass = self .properties [property ]
350352 value = self .cl .get (self .nodeid , property )
351353 if isinstance (propclass , hyperdb .Link ):
@@ -359,7 +361,7 @@ def do_download(self, property, **args):
359361 linkvalue = linkcl .get (value , k )
360362 l .append ('<a href="%s%s">%s</a>' % (linkcl , value , linkvalue ))
361363 return ', ' .join (l )
362- return '[Download: not a link]'
364+ return _ ( '[Download: not a link]' )
363365
364366
365367 def do_checklist (self , property , ** args ):
@@ -369,7 +371,7 @@ def do_checklist(self, property, **args):
369371 propclass = self .properties [property ]
370372 if (not isinstance (propclass , hyperdb .Link ) and not
371373 isinstance (propclass , hyperdb .Multilink )):
372- return '[Checklist: not a link]'
374+ return _ ( '[Checklist: not a link]' )
373375
374376 # get our current checkbox state
375377 if self .nodeid :
@@ -404,8 +406,8 @@ def do_checklist(self, property, **args):
404406 checked = 'checked'
405407 else :
406408 checked = ''
407- l .append ('[unselected]:<input type="checkbox" %s name="%s" '
408- 'value="-1">' % (checked , property ))
409+ l .append (_ ( '[unselected]:<input type="checkbox" %s name="%s" '
410+ 'value="-1">' ) % (checked , property ))
409411 return '\n ' .join (l )
410412
411413 def do_note (self , rows = 5 , cols = 80 ):
@@ -423,7 +425,7 @@ def do_list(self, property, reverse=0):
423425 '''
424426 propcl = self .properties [property ]
425427 if not isinstance (propcl , hyperdb .Multilink ):
426- return '[List: not a Multilink]'
428+ return _ ( '[List: not a Multilink]' )
427429 value = self .cl .get (self .nodeid , property )
428430 if reverse :
429431 value .reverse ()
@@ -445,14 +447,14 @@ def do_history(self, **args):
445447 ''' list the history of the item
446448 '''
447449 if self .nodeid is None :
448- return "[History: node doesn't exist]"
450+ return _ ( "[History: node doesn't exist]" )
449451
450452 l = ['<table width=100% border=0 cellspacing=0 cellpadding=2>' ,
451453 '<tr class="list-header">' ,
452- '<td><span class="list-item"><strong>Date</strong></span></td>' ,
453- '<td><span class="list-item"><strong>User</strong></span></td>' ,
454- '<td><span class="list-item"><strong>Action</strong></span></td>' ,
455- '<td><span class="list-item"><strong>Args</strong></span></td>' ]
454+ _ ( '<td><span class="list-item"><strong>Date</strong></span></td>' ) ,
455+ _ ( '<td><span class="list-item"><strong>User</strong></span></td>' ) ,
456+ _ ( '<td><span class="list-item"><strong>Action</strong></span></td>' ) ,
457+ _ ( '<td><span class="list-item"><strong>Args</strong></span></td>' ) ]
456458
457459 for id , date , user , action , args in self .cl .history (self .nodeid ):
458460 l .append ('<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>' % (
@@ -465,11 +467,11 @@ def do_submit(self):
465467 ''' add a submit button for the item
466468 '''
467469 if self .nodeid :
468- return '<input type="submit" value="Submit Changes">'
470+ return _ ( '<input type="submit" value="Submit Changes">' )
469471 elif self .form is not None :
470- return '<input type="submit" value="Submit New Entry">'
472+ return _ ( '<input type="submit" value="Submit New Entry">' )
471473 else :
472- return '[Submit: not called from item]'
474+ return _ ( '[Submit: not called from item]' )
473475
474476
475477#
@@ -589,7 +591,7 @@ def render(self, filterspec={}, filter=[], columns=[], sort=[], group=[],
589591 for nodeid in nodeids :
590592 # check for a group heading
591593 if group_names :
592- this_group = [self .cl .get (nodeid , name , '[no value]' ) for name in group_names ]
594+ this_group = [self .cl .get (nodeid , name , _ ( '[no value]' ) ) for name in group_names ]
593595 if this_group != old_group :
594596 l = []
595597 for name in group_names :
@@ -599,7 +601,8 @@ def render(self, filterspec={}, filter=[], columns=[], sort=[], group=[],
599601 key = group_cl .getkey ()
600602 value = self .cl .get (nodeid , name )
601603 if value is None :
602- l .append ('[unselected %s]' % prop .classname )
604+ l .append (_ ('[unselected %(classname)s]' )% {
605+ 'classname' : prop .classname })
603606 else :
604607 l .append (group_cl .get (self .cl .get (nodeid ,
605608 name ), key ))
@@ -609,9 +612,9 @@ def render(self, filterspec={}, filter=[], columns=[], sort=[], group=[],
609612 for value in self .cl .get (nodeid , name ):
610613 l .append (group_cl .get (value , key ))
611614 else :
612- value = self .cl .get (nodeid , name , '[no value]' )
615+ value = self .cl .get (nodeid , name , _ ( '[no value]' ) )
613616 if value is None :
614- value = '[empty %s]' % name
617+ value = _ ( '[empty %(name) s]' ) % locals ()
615618 else :
616619 value = str (value )
617620 l .append (value )
@@ -654,12 +657,12 @@ def filter_section(self, template, filter, columns, group, all_filters,
654657 # display the filter section
655658 w ('<table width=100% border=0 cellspacing=0 cellpadding=2>' )
656659 w ('<tr class="location-bar">' )
657- w (' <th align="left" colspan="2">Filter specification...</th>' )
660+ w (_ ( ' <th align="left" colspan="2">Filter specification...</th>' ) )
658661 w ('</tr>' )
659662 replace = IndexTemplateReplace (self .globals , locals (), filter )
660663 w (replace .go (template ))
661664 w ('<tr class="location-bar"><td width="1%%"> </td>' )
662- w ('<td><input type="submit" name="action" value="Redisplay"></td></tr>' )
665+ w (_ ( '<td><input type="submit" name="action" value="Redisplay"></td></tr>' ) )
663666 w ('</table>' )
664667
665668 # now add in the filter/columns/group/etc config table form
@@ -685,9 +688,9 @@ def filter_section(self, template, filter, columns, group, all_filters,
685688 w ('<input type="hidden" name=":group" value="%s">' % name )
686689
687690 # TODO: The widget style can go into the stylesheet
688- w ('<th align="left" colspan=%s>'
691+ w (_ ( '<th align="left" colspan=%s>'
689692 '<input style="height : 1em; width : 1em; font-size: 12pt" type="submit" name="action" value="%s"> View '
690- 'customisation...</th></tr>\n ' % (len (names )+ 1 , action ))
693+ 'customisation...</th></tr>\n ' ) % (len (names )+ 1 , action ))
691694
692695 if not show_customization :
693696 w ('</table>\n ' )
@@ -700,8 +703,7 @@ def filter_section(self, template, filter, columns, group, all_filters,
700703
701704 # Filter
702705 if all_filters :
703- w ('<tr><th width="1%" align=right class="location-bar">'
704- 'Filters</th>\n ' )
706+ w (_ ('<tr><th width="1%" align=right class="location-bar">Filters</th>\n ' ))
705707 for name in names :
706708 if name not in all_filters :
707709 w ('<td> </td>' )
@@ -715,8 +717,7 @@ def filter_section(self, template, filter, columns, group, all_filters,
715717
716718 # Columns
717719 if all_columns :
718- w ('<tr><th width="1%" align=right class="location-bar">'
719- 'Columns</th>\n ' )
720+ w (_ ('<tr><th width="1%" align=right class="location-bar">Columns</th>\n ' ))
720721 for name in names :
721722 if name not in all_columns :
722723 w ('<td> </td>' )
@@ -729,8 +730,7 @@ def filter_section(self, template, filter, columns, group, all_filters,
729730 w ('</tr>\n ' )
730731
731732 # Grouping
732- w ('<tr><th width="1%" align=right class="location-bar">'
733- 'Grouping</th>\n ' )
733+ w (_ ('<tr><th width="1%" align=right class="location-bar">Grouping</th>\n ' ))
734734 for name in names :
735735 prop = self .properties [name ]
736736 if name not in all_columns :
@@ -745,7 +745,7 @@ def filter_section(self, template, filter, columns, group, all_filters,
745745
746746 w ('<tr class="location-bar"><td width="1%"> </td>' )
747747 w ('<td colspan="%s">' % len (names ))
748- w ('<input type="submit" name="action" value="Redisplay"></td>' )
748+ w (_ ( '<input type="submit" name="action" value="Redisplay"></td>' ) )
749749 w ('</tr>\n ' )
750750 w ('</table>\n ' )
751751
@@ -885,6 +885,14 @@ def render(self, form):
885885
886886#
887887# $Log: not supported by cvs2svn $
888+ # Revision 1.49 2001/12/20 15:43:01 rochecompaan
889+ # Features added:
890+ # . Multilink properties are now displayed as comma separated values in
891+ # a textbox
892+ # . The add user link is now only visible to the admin user
893+ # . Modified the mail gateway to reject submissions from unknown
894+ # addresses if ANONYMOUS_ACCESS is denied
895+ #
888896# Revision 1.48 2001/12/20 06:13:24 rochecompaan
889897# Bugs fixed:
890898# . Exception handling in hyperdb for strings-that-look-like numbers got
0 commit comments