Skip to content

Commit 9154875

Browse files
author
Roche Compaan
committed
Removed generation of change note from "sendmessage" in roundupdb.py.
The change note is now generated when the message is created.
1 parent e1c49c6 commit 9154875

File tree

5 files changed

+146
-80
lines changed

5 files changed

+146
-80
lines changed

roundup/cgi_client.py

Lines changed: 30 additions & 13 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: cgi_client.py,v 1.75 2001-12-04 01:25:08 richard Exp $
18+
# $Id: cgi_client.py,v 1.76 2001-12-05 14:26:44 rochecompaan Exp $
1919

2020
__doc__ = """
2121
WWW request handler (also used in the stand-alone server).
@@ -313,7 +313,7 @@ def shownode(self, message=None):
313313
self.nodeid)
314314

315315
# set status to chatting if 'unread' or 'resolved'
316-
if 'status' not in changed:
316+
if 'status' not in changed.keys():
317317
try:
318318
# determine the id of 'unread','resolved' and 'chatting'
319319
unread_id = self.db.status.lookup('unread')
@@ -326,18 +326,21 @@ def shownode(self, message=None):
326326
props['status'] == unread_id or
327327
props['status'] == resolved_id):
328328
props['status'] = chatting_id
329-
changed.append('status')
329+
changed['status'] = chatting_id
330+
331+
# get the change note
332+
change_note = cl.generateChangeNote(self.nodeid, changed)
330333

331334
# make the changes
332335
cl.set(self.nodeid, **props)
333336

334337
# handle linked nodes and change message generation
335-
self._post_editnode(self.nodeid, changed)
338+
self._post_editnode(self.nodeid, change_note)
336339

337340
# and some nice feedback for the user
338341
if changed:
339342
message = _('%(changes)s edited ok')%{'changes':
340-
', '.join(changed)}
343+
', '.join(changed.keys())}
341344
else:
342345
message = _('nothing changed')
343346
except:
@@ -395,10 +398,10 @@ def showuser(self, message=None):
395398
del props['password']
396399
del changed[changed.index('password')]
397400
user.set(self.nodeid, **props)
398-
self._post_editnode(self.nodeid, changed)
401+
self._post_editnode(self.nodeid)
399402
# and some feedback for the user
400403
message = _('%(changes)s edited ok')%{'changes':
401-
', '.join(changed)}
404+
', '.join(changed.keys())}
402405
except:
403406
self.db.rollback()
404407
s = StringIO.StringIO()
@@ -437,9 +440,19 @@ def _createnode(self):
437440
'''
438441
cl = self.db.classes[self.classname]
439442
props, dummy = parsePropsFromForm(self.db, cl, self.form)
443+
444+
# set status to 'unread' if not specified - a status of '- no
445+
# selection -' doesn't make sense
446+
if not props.has_key('status'):
447+
try:
448+
unread_id = self.db.status.lookup('unread')
449+
except KeyError:
450+
pass
451+
else:
452+
props['status'] = unread_id
440453
return cl.create(**props)
441454

442-
def _post_editnode(self, nid, changes=None):
455+
def _post_editnode(self, nid, change_note=None):
443456
''' do the linking and message sending part of the node creation
444457
'''
445458
cn = self.classname
@@ -479,8 +492,6 @@ def _post_editnode(self, nid, changes=None):
479492
name=file.filename, content=file.file.read()))
480493
# and save the reference
481494
cl.set(nid, files=files)
482-
if changes is not None and 'file' not in changes:
483-
changes.append('file')
484495

485496
#
486497
# generate an edit message
@@ -513,7 +524,8 @@ def _post_editnode(self, nid, changes=None):
513524
' the web.\n')%{'classname': cn}
514525
m = [summary]
515526

516-
# TODO: append the change note!
527+
# append the change note
528+
m.append(change_note)
517529

518530
# now create the message
519531
content = '\n'.join(m)
@@ -1002,7 +1014,7 @@ def parsePropsFromForm(db, cl, form, nodeid=0):
10021014
'''Pull properties for the given class out of the form.
10031015
'''
10041016
props = {}
1005-
changed = []
1017+
changed = {}
10061018
keys = form.keys()
10071019
num_re = re.compile('^\d+$')
10081020
for key in keys:
@@ -1042,6 +1054,7 @@ def parsePropsFromForm(db, cl, form, nodeid=0):
10421054
link = cl.properties[key].classname
10431055
l = []
10441056
for entry in map(str, value):
1057+
if entry == '': continue
10451058
if not num_re.match(entry):
10461059
try:
10471060
entry = db.classes[link].lookup(entry)
@@ -1065,12 +1078,16 @@ def parsePropsFromForm(db, cl, form, nodeid=0):
10651078

10661079
# if changed, set it
10671080
if nodeid and value != existing:
1068-
changed.append(key)
1081+
changed[key] = value
10691082
props[key] = value
10701083
return props, changed
10711084

10721085
#
10731086
# $Log: not supported by cvs2svn $
1087+
# Revision 1.75 2001/12/04 01:25:08 richard
1088+
# Added some rollbacks where we were catching exceptions that would otherwise
1089+
# have stopped committing.
1090+
#
10741091
# Revision 1.74 2001/12/02 05:06:16 richard
10751092
# . We now use weakrefs in the Classes to keep the database reference, so
10761093
# the close() method on the database is no longer needed.

roundup/mailgw.py

Lines changed: 87 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class node. Any parts of other types are each stored in separate files
7373
an exception, the original message is bounced back to the sender with the
7474
explanatory message given in the exception.
7575
76-
$Id: mailgw.py,v 1.39 2001-12-02 05:06:16 richard Exp $
76+
$Id: mailgw.py,v 1.40 2001-12-05 14:26:44 rochecompaan Exp $
7777
'''
7878

7979

@@ -342,9 +342,26 @@ def handle_message(self, message):
342342
Subject was: "%s"
343343
'''%(key, message, subject)
344344
elif isinstance(proptype, hyperdb.Link):
345-
props[key] = value.strip()
345+
link = self.db.classes[proptype.classname]
346+
propkey = link.labelprop(default_to_id=1)
347+
try:
348+
props[key] = link.get(value.strip(), propkey)
349+
except:
350+
props[key] = link.lookup(value.strip())
346351
elif isinstance(proptype, hyperdb.Multilink):
347-
props[key] = [x.strip() for x in value.split(',')]
352+
link = self.db.classes[proptype.classname]
353+
propkey = link.labelprop(default_to_id=1)
354+
l = [x.strip() for x in value.split(',')]
355+
for item in l:
356+
try:
357+
v = link.get(item, propkey)
358+
except:
359+
v = link.lookup(item)
360+
if props.has_key(key):
361+
props[key].append(v)
362+
else:
363+
props[key] = [v]
364+
348365

349366
#
350367
# handle the users
@@ -459,20 +476,6 @@ def handle_message(self, message):
459476
# the newly created "msg" node is added to the "messages" property
460477
# for that item, and any new "file" nodes are added to the "files"
461478
# property for the item.
462-
message_id = self.db.msg.create(author=author,
463-
recipients=recipients, date=date.Date('.'), summary=summary,
464-
content=content, files=files)
465-
try:
466-
messages = cl.get(nodeid, 'messages')
467-
except IndexError:
468-
raise MailUsageError, '''
469-
The node specified by the designator in the subject of your message ("%s")
470-
does not exist.
471-
472-
Subject was: "%s"
473-
'''%(nodeid, subject)
474-
messages.append(message_id)
475-
props['messages'] = messages
476479

477480
# if the message is currently 'unread' or 'resolved', then set
478481
# it to 'chatting'
@@ -490,22 +493,43 @@ def handle_message(self, message):
490493
props['status'] == resolved_id):
491494
props['status'] = chatting_id
492495

493-
# add nosy in arguments to issue's nosy list, don't replace
494-
if props.has_key('nosy'):
495-
n = {}
496-
for nid in cl.get(nodeid, 'nosy'):
497-
n[nid] = 1
498-
for value in props['nosy']:
499-
if self.db.hasnode('user', value):
500-
nid = value
501-
else:
502-
try:
503-
nid = self.db.user.lookup(value)
504-
except:
505-
continue
506-
if n.has_key(nid): continue
507-
n[nid] = 1
508-
props['nosy'] = n.keys()
496+
# add nosy in arguments to issue's nosy list
497+
if not props.has_key('nosy'): props['nosy'] = []
498+
n = {}
499+
for nid in cl.get(nodeid, 'nosy'):
500+
n[nid] = 1
501+
for value in props['nosy']:
502+
if self.db.hasnode('user', value):
503+
nid = value
504+
else:
505+
continue
506+
if n.has_key(nid): continue
507+
n[nid] = 1
508+
props['nosy'] = n.keys()
509+
try:
510+
assignedto = self.db.user.lookup(props['assignedto'])
511+
if assignedto not in props['nosy']:
512+
props['nosy'].append(assignedto)
513+
except:
514+
pass
515+
516+
change_note = cl.generateChangeNote(nodeid, props)
517+
content += change_note
518+
519+
message_id = self.db.msg.create(author=author,
520+
recipients=recipients, date=date.Date('.'), summary=summary,
521+
content=content, files=files)
522+
try:
523+
messages = cl.get(nodeid, 'messages')
524+
except IndexError:
525+
raise MailUsageError, '''
526+
The node specified by the designator in the subject of your message ("%s")
527+
does not exist.
528+
529+
Subject was: "%s"
530+
'''%(nodeid, subject)
531+
messages.append(message_id)
532+
props['messages'] = messages
509533

510534
# now apply the changes
511535
try:
@@ -542,9 +566,22 @@ def handle_message(self, message):
542566

543567
# pre-load the messages list and nosy list
544568
props['messages'] = [message_id]
545-
props['nosy'] = props.get('nosy', []) + recipients
546-
props['nosy'].append(author)
547-
props['nosy'].sort()
569+
nosy = props.get('nosy', [])
570+
n = {}
571+
for value in nosy:
572+
if self.db.hasnode('user', value):
573+
nid = value
574+
else:
575+
try:
576+
nid = self.db.user.lookup(value)
577+
except:
578+
continue
579+
if n.has_key(nid): continue
580+
n[nid] = 1
581+
props['nosy'] = n.keys() + recipients
582+
if not n.has_key(author):
583+
props['nosy'].append(author)
584+
n[author] = 1
548585

549586
# and attempt to create the new node
550587
try:
@@ -598,6 +635,20 @@ def parseContent(content, blank_line=re.compile(r'[\r\n]+\s*[\r\n]+'),
598635

599636
#
600637
# $Log: not supported by cvs2svn $
638+
# Revision 1.39 2001/12/02 05:06:16 richard
639+
# . We now use weakrefs in the Classes to keep the database reference, so
640+
# the close() method on the database is no longer needed.
641+
# I bumped the minimum python requirement up to 2.1 accordingly.
642+
# . #487480 ] roundup-server
643+
# . #487476 ] INSTALL.txt
644+
#
645+
# I also cleaned up the change message / post-edit stuff in the cgi client.
646+
# There's now a clearly marked "TODO: append the change note" where I believe
647+
# the change note should be added there. The "changes" list will obviously
648+
# have to be modified to be a dict of the changes, or somesuch.
649+
#
650+
# More testing needed.
651+
#
601652
# Revision 1.38 2001/12/01 07:17:50 richard
602653
# . We now have basic transaction support! Information is only written to
603654
# the database when the commit() method is called. Only the anydbm

0 commit comments

Comments
 (0)