comparison roundup/cgi/templating.py @ 2614:c64ea31a569b

merge from HEAD, with some additional code re-arranging
author Richard Jones <richard@users.sourceforge.net>
date Thu, 22 Jul 2004 00:43:55 +0000
parents 5f52d113de0c
children 11811b313459
comparison
equal deleted inserted replaced
2612:7cf56f5b3991 2614:c64ea31a569b
760 return [] 760 return []
761 761
762 def history(self, direction='descending', dre=re.compile('^\d+$')): 762 def history(self, direction='descending', dre=re.compile('^\d+$')):
763 self.view_check() 763 self.view_check()
764 764
765 l = ['<table class="history">' 765 # pre-load the history with the current state
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>']
774 current = {} 766 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
776 history = self._klass.history(self._nodeid) 789 history = self._klass.history(self._nodeid)
777 history.sort() 790 history.sort()
791 history.reverse()
792
778 timezone = self._db.getUserTimezone() 793 timezone = self._db.getUserTimezone()
779 if direction == 'descending': 794 l = []
780 history.reverse() 795 comments = {}
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])
802
803 for id, evt_date, user, action, args in history: 796 for id, evt_date, user, action, args in history:
804 date_s = str(evt_date.local(timezone)).replace("."," ") 797 date_s = str(evt_date.local(timezone)).replace("."," ")
805 arg_s = '' 798 arg_s = ''
806 if action == 'link' and type(args) == type(()): 799 if action == 'link' and type(args) == type(()):
807 if len(args) == 3: 800 if len(args) == 3:
974 if comments: 967 if comments:
975 l.append(self._( 968 l.append(self._(
976 '<tr><td colspan=4><strong>Note:</strong></td></tr>')) 969 '<tr><td colspan=4><strong>Note:</strong></td></tr>'))
977 for entry in comments.values(): 970 for entry in comments.values():
978 l.append('<tr><td colspan=4>%s</td></tr>'%entry) 971 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>']
979 l.append('</table>') 985 l.append('</table>')
980 return '\n'.join(l) 986 return '\n'.join(l)
981 987
982 def renderQueryForm(self): 988 def renderQueryForm(self):
983 ''' Render this item, which is a query, as a search form. 989 ''' Render this item, which is a query, as a search form.

Roundup Issue Tracker: http://roundup-tracker.org/