|
15 | 15 | # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
16 | 16 | # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
17 | 17 | # |
18 | | -# $Id: roundupdb.py,v 1.23 2001-11-27 03:17:13 richard Exp $ |
| 18 | +# $Id: roundupdb.py,v 1.24 2001-11-30 11:29:04 rochecompaan Exp $ |
19 | 19 |
|
20 | 20 | __doc__ = """ |
21 | 21 | Extending hyperdb with types specific to issue-tracking. |
@@ -268,7 +268,7 @@ def addmessage(self, nodeid, summary, text): |
268 | 268 | appended to the "messages" field of the specified issue. |
269 | 269 | """ |
270 | 270 |
|
271 | | - def sendmessage(self, nodeid, msgid): |
| 271 | + def sendmessage(self, nodeid, msgid, oldvalues): |
272 | 272 | """Send a message to the members of an issue's nosy list. |
273 | 273 |
|
274 | 274 | The message is sent only to users on the nosy list who are not |
@@ -326,26 +326,33 @@ def sendmessage(self, nodeid, msgid): |
326 | 326 | authaddr = ' <%s>'%authaddr |
327 | 327 | else: |
328 | 328 | authaddr = '' |
| 329 | + |
| 330 | + # get the change note |
| 331 | + if oldvalues: |
| 332 | + change_note = self.generateChangeNote(nodeid, oldvalues) |
| 333 | + else: |
| 334 | + change_note = '' |
| 335 | + |
329 | 336 | # make the message body |
330 | 337 | m = [''] |
331 | 338 |
|
332 | 339 | # put in roundup's signature |
333 | 340 | if self.EMAIL_SIGNATURE_POSITION == 'top': |
334 | | - m.append(self.email_signature(nodeid, msgid)) |
| 341 | + m.append(self.email_signature(nodeid, msgid, change_note)) |
335 | 342 |
|
336 | 343 | # add author information |
337 | | - if len(self.db.issue.get(nodeid, 'messages')) == 1: |
338 | | - m.append("New submission from %s%s:"%(authname, authaddr)) |
339 | | - else: |
| 344 | + if oldvalues: |
340 | 345 | m.append("%s%s added the comment:"%(authname, authaddr)) |
| 346 | + else: |
| 347 | + m.append("New submission from %s%s:"%(authname, authaddr)) |
341 | 348 | m.append('') |
342 | 349 |
|
343 | 350 | # add the content |
344 | 351 | m.append(self.db.msg.get(msgid, 'content')) |
345 | 352 |
|
346 | | - # "list information" footer |
| 353 | + # put in roundup's signature |
347 | 354 | if self.EMAIL_SIGNATURE_POSITION == 'bottom': |
348 | | - m.append(self.email_signature(nodeid, msgid)) |
| 355 | + m.append(self.email_signature(nodeid, msgid, change_note)) |
349 | 356 |
|
350 | 357 | # get the files for this message |
351 | 358 | files = self.db.msg.get(msgid, 'files') |
@@ -406,16 +413,90 @@ def sendmessage(self, nodeid, msgid): |
406 | 413 | raise MessageSendError, \ |
407 | 414 | "Couldn't send confirmation email: %s"%value |
408 | 415 |
|
409 | | - def email_signature(self, nodeid, msgid): |
| 416 | + def email_signature(self, nodeid, msgid, change_note): |
410 | 417 | ''' Add a signature to the e-mail with some useful information |
411 | 418 | ''' |
412 | 419 | web = self.ISSUE_TRACKER_WEB + 'issue'+ nodeid |
413 | 420 | email = '"%s" <%s>'%(self.INSTANCE_NAME, self.ISSUE_TRACKER_EMAIL) |
414 | 421 | line = '_' * max(len(web), len(email)) |
415 | | - return '%s\n%s\n%s\n%s'%(line, email, web, line) |
| 422 | + return '%s\n%s\n%s\n%s\n%s'%(line, email, web, change_note, line) |
| 423 | + |
| 424 | + def generateChangeNote(self, nodeid, oldvalues): |
| 425 | + """Generate a change note that lists property changes |
| 426 | + """ |
| 427 | + cn = self.classname |
| 428 | + cl = self.db.classes[cn] |
| 429 | + changed = {} |
| 430 | + props = cl.getprops(protected=0) |
| 431 | + |
| 432 | + # determine what changed |
| 433 | + for key in props.keys(): |
| 434 | + if key in ['files','messages']: continue |
| 435 | + new_value = cl.get(nodeid, key) |
| 436 | + # the old value might be non existent |
| 437 | + try: |
| 438 | + old_value = oldvalues[key] |
| 439 | + if type(old_value) is type([]): |
| 440 | + old_value.sort() |
| 441 | + new_value.sort() |
| 442 | + if old_value != new_value: |
| 443 | + changed[key] = old_value |
| 444 | + except: |
| 445 | + old_value = None |
| 446 | + changed[key] = old_value |
| 447 | + |
| 448 | + # list the changes |
| 449 | + m = [] |
| 450 | + for propname, oldvalue in changed.items(): |
| 451 | + prop = cl.properties[propname] |
| 452 | + value = cl.get(nodeid, propname, None) |
| 453 | + change = '%s -> %s'%(oldvalue, value) |
| 454 | + if isinstance(prop, hyperdb.Link): |
| 455 | + link = self.db.classes[prop.classname] |
| 456 | + key = link.labelprop(default_to_id=1) |
| 457 | + if key: |
| 458 | + if value: |
| 459 | + value = link.get(value, key) |
| 460 | + else: |
| 461 | + value = '' |
| 462 | + if oldvalue: |
| 463 | + oldvalue = link.get(oldvalue, key) |
| 464 | + else: |
| 465 | + oldvalue = '' |
| 466 | + change = '%s -> %s'%(oldvalue, value) |
| 467 | + elif isinstance(prop, hyperdb.Multilink): |
| 468 | + if value is None: value = [] |
| 469 | + l = [] |
| 470 | + link = self.db.classes[prop.classname] |
| 471 | + key = link.labelprop(default_to_id=1) |
| 472 | + if oldvalue is None: oldvalue = [] |
| 473 | + # check for additions |
| 474 | + for entry in value: |
| 475 | + if entry in oldvalue: continue |
| 476 | + if key: |
| 477 | + l.append(link.get(entry, key)) |
| 478 | + else: |
| 479 | + l.append(entry) |
| 480 | + if l: |
| 481 | + change = '+%s'%(', '.join(l)) |
| 482 | + l = [] |
| 483 | + # check for removals |
| 484 | + for entry in oldvalue: |
| 485 | + if entry in value: continue |
| 486 | + if key: |
| 487 | + l.append(link.get(entry, key)) |
| 488 | + else: |
| 489 | + l.append(entry) |
| 490 | + if l: |
| 491 | + change = change + ' -%s'%(', '.join(l)) |
| 492 | + m.append('%s: %s'%(propname, change)) |
| 493 | + return '\n'.join(m) |
416 | 494 |
|
417 | 495 | # |
418 | 496 | # $Log: not supported by cvs2svn $ |
| 497 | +# Revision 1.23 2001/11/27 03:17:13 richard |
| 498 | +# oops |
| 499 | +# |
419 | 500 | # Revision 1.22 2001/11/27 03:00:50 richard |
420 | 501 | # couple of bugfixes from latest patch integration |
421 | 502 | # |
|
0 commit comments