1- # $Id: htmltemplate.py,v 1.8 2001-07-29 07:01:39 richard Exp $
1+ # $Id: htmltemplate.py,v 1.9 2001-07-29 08:27:40 richard Exp $
22
33import os , re , StringIO , urllib , cgi , errno
44
55import hyperdb , date
66
77class Base :
8- def __init__ (self , db , templates , classname , nodeid = None , form = None ):
8+ def __init__ (self , db , templates , classname , nodeid = None , form = None ,
9+ filterspec = None ):
910 # TODO: really not happy with the way templates is passed on here
1011 self .db , self .templates = db , templates
1112 self .classname , self .nodeid = classname , nodeid
12- self .form = form
13+ self .form , self . filterspec = form , filterspec
1314 self .cl = self .db .classes [self .classname ]
1415 self .properties = self .cl .getprops ()
1516
@@ -57,11 +58,16 @@ class Field(Base):
5758 to be edited
5859 '''
5960 def __call__ (self , property , size = None , height = None , showid = 0 ):
60- if not self .nodeid and self .form is None :
61+ if not self .nodeid and self .form and self . filterspec is None :
6162 return '[Field: not called from item]'
6263 propclass = self .properties [property ]
6364 if self .nodeid :
6465 value = self .cl .get (self .nodeid , property )
66+ elif self .filterspec is not None :
67+ if propclass .isMultilinkType :
68+ value = self .filterspec .get (property , [])
69+ else :
70+ value = self .filterspec .get (property , '' )
6571 else :
6672 # TODO: pull the value from the form
6773 if propclass .isMultilinkType : value = []
@@ -265,6 +271,8 @@ def __call__(self, property, **args):
265271 propclass = self .properties [property ]
266272 if self .nodeid :
267273 value = self .cl .get (self .nodeid , property )
274+ elif self .filterspec is not None :
275+ value = self .filterspec .get (property , [])
268276 else :
269277 value = []
270278 if propclass .isLinkType or propclass .isMultilinkType :
@@ -273,7 +281,7 @@ def __call__(self, property, **args):
273281 k = linkcl .labelprop ()
274282 for optionid in linkcl .list ():
275283 option = linkcl .get (optionid , k )
276- if optionid in value :
284+ if optionid in value or option in value :
277285 checked = 'checked'
278286 else :
279287 checked = ''
@@ -405,22 +413,23 @@ def index(client, templates, db, classname, filterspec={}, filter=[],
405413 columns = [], sort = [], group = [], show_display_form = 1 , nodeids = None ,
406414 col_re = re .compile (r'<property\s+name="([^>]+)">' )):
407415 globals = {
408- 'plain' : Plain (db , templates , classname , form = {} ),
409- 'field' : Field (db , templates , classname , form = {} ),
410- 'menu' : Menu (db , templates , classname , form = {} ),
411- 'link' : Link (db , templates , classname , form = {} ),
412- 'count' : Count (db , templates , classname , form = {} ),
413- 'reldate' : Reldate (db , templates , classname , form = {} ),
414- 'download' : Download (db , templates , classname , form = {} ),
415- 'checklist' : Checklist (db , templates , classname , form = {} ),
416- 'list' : List (db , templates , classname , form = {} ),
417- 'history' : History (db , templates , classname , form = {} ),
418- 'submit' : Submit (db , templates , classname , form = {} ),
419- 'note' : Note (db , templates , classname , form = {} )
416+ 'plain' : Plain (db , templates , classname , filterspec = filterspec ),
417+ 'field' : Field (db , templates , classname , filterspec = filterspec ),
418+ 'menu' : Menu (db , templates , classname , filterspec = filterspec ),
419+ 'link' : Link (db , templates , classname , filterspec = filterspec ),
420+ 'count' : Count (db , templates , classname , filterspec = filterspec ),
421+ 'reldate' : Reldate (db , templates , classname , filterspec = filterspec ),
422+ 'download' : Download (db , templates , classname , filterspec = filterspec ),
423+ 'checklist' : Checklist (db , templates , classname , filterspec = filterspec ),
424+ 'list' : List (db , templates , classname , filterspec = filterspec ),
425+ 'history' : History (db , templates , classname , filterspec = filterspec ),
426+ 'submit' : Submit (db , templates , classname , filterspec = filterspec ),
427+ 'note' : Note (db , templates , classname , filterspec = filterspec )
420428 }
421429 cl = db .classes [classname ]
422430 properties = cl .getprops ()
423431 w = client .write
432+ w ('<form>' )
424433
425434 try :
426435 template = open (os .path .join (templates , classname + '.filter' )).read ()
@@ -431,28 +440,26 @@ def index(client, templates, db, classname, filterspec={}, filter=[],
431440 all_filters = []
432441 if template and filter :
433442 # display the filter section
434- w ('<form>' )
435443 w ('<table width=100% border=0 cellspacing=0 cellpadding=2>' )
436444 w ('<tr class="location-bar">' )
437445 w (' <th align="left" colspan="2">Filter specification...</th>' )
438446 w ('</tr>' )
439447 replace = IndexTemplateReplace (globals , locals (), filter )
440448 w (replace .go (template ))
441- if columns :
442- w ('<input type="hidden" name=":columns" value="%s">' % ',' .join (columns ))
443- if filter :
444- w ('<input type="hidden" name=":filter" value="%s">' % ',' .join (filter ))
445- if sort :
446- w ('<input type="hidden" name=":sort" value="%s">' % ',' .join (sort ))
447- if group :
448- w ('<input type="hidden" name=":group" value="%s">' % ',' .join (group ))
449- for k , v in filterspec .items ():
450- if type (v ) == type ([]): v = ',' .join (v )
451- w ('<input type="hidden" name="%s" value="%s">' % (k , v ))
452449 w ('<tr class="location-bar"><td width="1%%"> </td>' )
453450 w ('<td><input type="submit" value="Redisplay"></td></tr>' )
454451 w ('</table>' )
455- w ('</form>' )
452+
453+ # If the filters aren't being displayed, then hide their current
454+ # value in the form
455+ if not filter :
456+ for k , v in filterspec .items ():
457+ if type (v ) == type ([]): v = ',' .join (v )
458+ w ('<input type="hidden" name="%s" value="%s">' % (k , v ))
459+
460+ # make sure that the sorting doesn't get lost either
461+ if sort :
462+ w ('<input type="hidden" name=":sort" value="%s">' % ',' .join (sort ))
456463
457464 # XXX deviate from spec here ...
458465 # load the index section template and figure the default columns from it
@@ -540,13 +547,8 @@ def index(client, templates, db, classname, filterspec={}, filter=[],
540547 return
541548
542549 # now add in the filter/columns/group/etc config table form
543- w ('<p><form> ' )
550+ w ('<p>' )
544551 w ('<table width=100% border=0 cellspacing=0 cellpadding=2>' )
545- for k ,v in filterspec .items ():
546- if type (v ) == type ([]): v = ',' .join (v )
547- w ('<input type="hidden" name="%s" value="%s">' % (k , v ))
548- if sort :
549- w ('<input type="hidden" name=":sort" value="%s">' % ',' .join (sort ))
550552 names = []
551553 for name in cl .getprops ().keys ():
552554 if name in all_filters or name in all_columns :
@@ -707,6 +709,9 @@ def newitem(client, templates, db, classname, form, replace=re.compile(
707709
708710#
709711# $Log: not supported by cvs2svn $
712+ # Revision 1.8 2001/07/29 07:01:39 richard
713+ # Added vim command to all source so that we don't get no steenkin' tabs :)
714+ #
710715# Revision 1.7 2001/07/29 05:36:14 richard
711716# Cleanup of the link label generation.
712717#
0 commit comments