|
15 | 15 | # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
16 | 16 | # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
17 | 17 | # |
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 $ |
19 | 19 |
|
20 | 20 | __doc__ = """ |
21 | 21 | Template engine. |
@@ -184,9 +184,9 @@ def sortfunc(a, b, cl=linkcl): |
184 | 184 | list.sort(sortfunc) |
185 | 185 | l = [] |
186 | 186 | # 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 |
188 | 188 | if not showid: |
189 | | - k = linkcl.labelprop() |
| 189 | + k = linkcl.labelprop() |
190 | 190 | value = [linkcl.get(v, k) for v in value] |
191 | 191 | if size is None: |
192 | 192 | size = '10' |
@@ -439,41 +439,138 @@ def do_list(self, property, reverse=0): |
439 | 439 | return fp.getvalue() |
440 | 440 |
|
441 | 441 | # XXX new function |
442 | | - def do_history(self, **args): |
| 442 | + def do_history(self, direction='descending'): |
443 | 443 | ''' 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. |
444 | 448 | ''' |
445 | 449 | if self.nodeid is None: |
446 | 450 | return _("[History: node doesn't exist]") |
447 | 451 |
|
448 | 452 | l = ['<table width=100% border=0 cellspacing=0 cellpadding=2>', |
449 | 453 | '<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(()): |
459 | 468 | 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) |
461 | 472 | else: |
462 | 473 | 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 = [] |
464 | 485 | 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]))) |
470 | 555 | 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) |
472 | 561 | 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(' ', ' ') |
| 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) |
477 | 574 | l.append('</table>') |
478 | 575 | return '\n'.join(l) |
479 | 576 |
|
@@ -903,6 +1000,9 @@ def render(self, form): |
903 | 1000 |
|
904 | 1001 | # |
905 | 1002 | # $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 | +# |
906 | 1006 | # Revision 1.59 2002/01/17 07:58:24 grubert |
907 | 1007 | # . display links a html link in history. |
908 | 1008 | # |
|
0 commit comments