@@ -762,44 +762,37 @@ def journal(self, direction='descending'):
762762 def history (self , direction = 'descending' , dre = re .compile ('^\d+$' )):
763763 self .view_check ()
764764
765- l = ['<table class="history">'
766- '<tr><th colspan="4" class="header">' ,
767- self ._ ('History' ),
768- '</th></tr><tr>' ,
769- self ._ ('<th>Date</th>' ),
770- self ._ ('<th>User</th>' ),
771- self ._ ('<th>Action</th>' ),
772- self ._ ('<th>Args</th>' ),
773- '</tr>' ]
765+ # pre-load the history with the current state
774766 current = {}
775- comments = {}
767+ for prop_n in self ._props .keys ():
768+ prop = self [prop_n ]
769+ if not isinstance (prop , HTMLProperty ):
770+ continue
771+ current [prop_n ] = prop .plain ()
772+ # make link if hrefable
773+ if (self ._props .has_key (prop_n ) and
774+ isinstance (self ._props [prop_n ], hyperdb .Link )):
775+ classname = self ._props [prop_n ].classname
776+ try :
777+ template = find_template (self ._db .config .TEMPLATES ,
778+ classname , 'item' )
779+ if template [1 ].startswith ('_generic' ):
780+ raise NoTemplate , 'not really...'
781+ except NoTemplate :
782+ pass
783+ else :
784+ id = self ._klass .get (self ._nodeid , prop_n , None )
785+ current [prop_n ] = '<a href="%s%s">%s</a>' % (
786+ classname , id , current [prop_n ])
787+
788+ # get the journal, sort and reverse
776789 history = self ._klass .history (self ._nodeid )
777790 history .sort ()
778- timezone = self ._db .getUserTimezone ()
779- if direction == 'descending' :
780- history .reverse ()
781- # pre-load the history with the current state
782- for prop_n in self ._props .keys ():
783- prop = self [prop_n ]
784- if not isinstance (prop , HTMLProperty ):
785- continue
786- current [prop_n ] = prop .plain ()
787- # make link if hrefable
788- if (self ._props .has_key (prop_n ) and
789- isinstance (self ._props [prop_n ], hyperdb .Link )):
790- classname = self ._props [prop_n ].classname
791- try :
792- template = find_template (self ._db .config .TEMPLATES ,
793- classname , 'item' )
794- if template [1 ].startswith ('_generic' ):
795- raise NoTemplate , 'not really...'
796- except NoTemplate :
797- pass
798- else :
799- id = self ._klass .get (self ._nodeid , prop_n , None )
800- current [prop_n ] = '<a href="%s%s">%s</a>' % (
801- classname , id , current [prop_n ])
791+ history .reverse ()
802792
793+ timezone = self ._db .getUserTimezone ()
794+ l = []
795+ comments = {}
803796 for id , evt_date , user , action , args in history :
804797 date_s = str (evt_date .local (timezone )).replace ("." ," " )
805798 arg_s = ''
@@ -976,6 +969,19 @@ def history(self, direction='descending', dre=re.compile('^\d+$')):
976969 '<tr><td colspan=4><strong>Note:</strong></td></tr>' ))
977970 for entry in comments .values ():
978971 l .append ('<tr><td colspan=4>%s</td></tr>' % entry )
972+
973+ if direction == 'ascending' :
974+ l .reverse ()
975+
976+ l [0 :0 ] = ['<table class="history">'
977+ '<tr><th colspan="4" class="header">' ,
978+ self ._ ('History' ),
979+ '</th></tr><tr>' ,
980+ self ._ ('<th>Date</th>' ),
981+ self ._ ('<th>User</th>' ),
982+ self ._ ('<th>Action</th>' ),
983+ self ._ ('<th>Args</th>' ),
984+ '</tr>' ]
979985 l .append ('</table>' )
980986 return '\n ' .join (l )
981987
0 commit comments