Skip to content

Commit 051ccd6

Browse files
author
Richard Jones
committed
much nicer history display (actualy real handling of property types etc)
1 parent ad9a4ad commit 051ccd6

File tree

2 files changed

+130
-27
lines changed

2 files changed

+130
-27
lines changed

CHANGES.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ This file contains the changes to the Roundup system over time. The entries
22
are given with the most recent entry first.
33

44
2002-01-?? - 0.4.0??
5-
. display superseder as html link in history.
6-
. display links as html link in history (e.g. message history back to issue).
5+
Feature:
6+
. much nicer history display (actualy real handling of property types etc)
7+
8+
Fixed:
79
. handle attachments with no name (eg tnef)
810

11+
912
2002-01-16 - 0.4.0b2
1013
Fixed:
1114
. #495392 ] empty nosy -patch

roundup/htmltemplate.py

Lines changed: 125 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: htmltemplate.py,v 1.60 2002-01-17 08:48:19 grubert Exp $
18+
# $Id: htmltemplate.py,v 1.61 2002-01-17 23:04:53 richard Exp $
1919

2020
__doc__ = """
2121
Template engine.
@@ -184,9 +184,9 @@ def sortfunc(a, b, cl=linkcl):
184184
list.sort(sortfunc)
185185
l = []
186186
# map the id to the label property
187-
# TODO: allow reversion to the older <select> box style display
187+
# TODO: allow reversion to the older <select> box style display
188188
if not showid:
189-
k = linkcl.labelprop()
189+
k = linkcl.labelprop()
190190
value = [linkcl.get(v, k) for v in value]
191191
if size is None:
192192
size = '10'
@@ -439,41 +439,138 @@ def do_list(self, property, reverse=0):
439439
return fp.getvalue()
440440

441441
# XXX new function
442-
def do_history(self, **args):
442+
def do_history(self, direction='descending'):
443443
''' list the history of the item
444+
445+
If "direction" is 'descending' then the most recent event will
446+
be displayed first. If it is 'ascending' then the oldest event
447+
will be displayed first.
444448
'''
445449
if self.nodeid is None:
446450
return _("[History: node doesn't exist]")
447451

448452
l = ['<table width=100% border=0 cellspacing=0 cellpadding=2>',
449453
'<tr class="list-header">',
450-
_('<td><span class="list-item"><strong>Date</strong></span></td>'),
451-
_('<td><span class="list-item"><strong>User</strong></span></td>'),
452-
_('<td><span class="list-item"><strong>Action</strong></span></td>'),
453-
_('<td><span class="list-item"><strong>Args</strong></span></td>')]
454-
455-
for id, date, user, action, args in self.cl.history(self.nodeid):
456-
date_s = str(date).replace("."," ")
457-
arg_s = ""
458-
if action=='link' and type(args)==type(()):
454+
_('<th align=left><span class="list-item">Date</span></th>'),
455+
_('<th align=left><span class="list-item">User</span></th>'),
456+
_('<th align=left><span class="list-item">Action</span></th>'),
457+
_('<th align=left><span class="list-item">Args</span></th>'),
458+
'</tr>']
459+
460+
comments = {}
461+
history = self.cl.history(self.nodeid)
462+
if direction == 'descending':
463+
history.reverse()
464+
for id, evt_date, user, action, args in history:
465+
date_s = str(evt_date).replace("."," ")
466+
arg_s = ''
467+
if action == 'link' and type(args) == type(()):
459468
if len(args) == 3:
460-
arg_s += '<a href="%s%s">%s%s %s</a>'% (args[0],args[1],args[0],args[1],args[2])
469+
linkcl, linkid, key = args
470+
arg_s += '<a href="%s%s">%s%s %s</a>'%(linkcl, linkid,
471+
linkcl, linkid, key)
461472
else:
462473
arg_s = str(arg)
463-
elif type(args)==type({}):
474+
475+
elif action == 'unlink' and type(args) == type(()):
476+
if len(args) == 3:
477+
linkcl, linkid, key = args
478+
arg_s += '<a href="%s%s">%s%s %s</a>'%(linkcl, linkid,
479+
linkcl, linkid, key)
480+
else:
481+
arg_s = str(arg)
482+
483+
elif type(args) == type({}):
484+
cell = []
464485
for k in args.keys():
465-
# special treatment of date, maybe links to files, authors, recipient ?
466-
if k=='superseder' and len(args[k])>0:
467-
arg_s += '<br />superseder: '
468-
for ssdr in args[k]:
469-
arg_s += '<a href="issue%s">issue%s</a>,'%(ssdr,ssdr)
486+
# try to get the relevant property and treat it
487+
# specially
488+
try:
489+
prop = self.properties[k]
490+
except:
491+
prop = None
492+
if prop is not None:
493+
if args[k] and (isinstance(prop, hyperdb.Multilink) or
494+
isinstance(prop, hyperdb.Link)):
495+
# figure what the link class is
496+
classname = prop.classname
497+
try:
498+
linkcl = self.db.classes[classname]
499+
except KeyError, message:
500+
labelprop = None
501+
comments[classname] = _('''The linked class
502+
%(classname)s no longer exists''')%locals()
503+
labelprop = linkcl.labelprop()
504+
505+
if isinstance(prop, hyperdb.Multilink) and \
506+
len(args[k]) > 0:
507+
ml = []
508+
for linkid in args[k]:
509+
label = classname + linkid
510+
# if we have a label property, try to use it
511+
# TODO: test for node existence even when
512+
# there's no labelprop!
513+
try:
514+
if labelprop is not None:
515+
label = linkcl.get(linkid, labelprop)
516+
except IndexError:
517+
comments['no_link'] = _('''<strike>The
518+
linked node no longer
519+
exists</strike>''')
520+
ml.append('<strike>%s</strike>'%label)
521+
else:
522+
ml.append('<a href="%s%s">%s</a>'%(
523+
classname, linkid, label))
524+
cell.append('%s:\n %s'%(k, ',\n '.join(ml)))
525+
elif isinstance(prop, hyperdb.Link) and args[k]:
526+
label = classname + args[k]
527+
# if we have a label property, try to use it
528+
# TODO: test for node existence even when
529+
# there's no labelprop!
530+
if labelprop is not None:
531+
try:
532+
label = linkcl.get(args[k], labelprop)
533+
except IndexError:
534+
comments['no_link'] = _('''<strike>The
535+
linked node no longer
536+
exists</strike>''')
537+
cell.append(' <strike>%s</strike>,\n'%label)
538+
else:
539+
cell.append(' <a href="%s%s">%s</a>,\n'%(
540+
classname, linkid, label))
541+
542+
elif isinstance(prop, hyperdb.Date) and args[k]:
543+
d = date.Date(args[k])
544+
cell.append('%s: %s'%(k, str(d)))
545+
546+
elif isinstance(prop, hyperdb.Interval) and args[k]:
547+
d = date.Interval(args[k])
548+
cell.append('%s: %s'%(k, str(d)))
549+
550+
elif not args[k]:
551+
cell.append('%s: (no value)\n'%k)
552+
553+
else:
554+
cell.append('%s: %s\n'%(k, str(args[k])))
470555
else:
471-
arg_s += '%s: %s,'%(k,str(args[k]))
556+
# property no longer exists
557+
comments['no_exist'] = _('''<em>The indicated property
558+
no longer exists</em>''')
559+
cell.append('<em>%s: %s</em>\n'%(k, str(args[k])))
560+
arg_s = '<br />'.join(cell)
472561
else:
473-
arg_s = str(args)
474-
# shouldnt _() be used ?
475-
l.append('<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>'%(
476-
date_s, user, action, arg_s))
562+
# unkown event!!
563+
comments['unknown'] = _('''<strong><em>This event is not
564+
handled by the history display!</em></strong>''')
565+
arg_s = '<strong><em>' + str(args) + '</em></strong>'
566+
date_s = date_s.replace(' ', '&nbsp;')
567+
l.append('<tr><td valign=top>%s</td><td valign=top>%s</td>'
568+
'<td valign=top>%s</td><td valign=top>%s</td></tr>'%(date_s,
569+
user, action, arg_s))
570+
if comments:
571+
l.append(_('<tr><td colspan=4><strong>Note:</strong></td></tr>'))
572+
for entry in comments.values():
573+
l.append('<tr><td colspan=4>%s</td></tr>'%entry)
477574
l.append('</table>')
478575
return '\n'.join(l)
479576

@@ -903,6 +1000,9 @@ def render(self, form):
9031000

9041001
#
9051002
# $Log: not supported by cvs2svn $
1003+
# Revision 1.60 2002/01/17 08:48:19 grubert
1004+
# . display superseder as html link in history.
1005+
#
9061006
# Revision 1.59 2002/01/17 07:58:24 grubert
9071007
# . display links a html link in history.
9081008
#

0 commit comments

Comments
 (0)