Code

Roundupdb now appends "mailing list" information to its messages which
[roundup.git] / roundup / cgi_client.py
index 3e2361e6c53500ef29b397c414f477a0ecf84f5b..7d18ef97b7ea64b6a2e9944fc082de646206569c 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: cgi_client.py,v 1.13 2001-07-30 08:12:17 richard Exp $
+# $Id: cgi_client.py,v 1.17 2001-08-02 06:38:17 richard Exp $
 
 import os, cgi, pprint, StringIO, urlparse, re, traceback, mimetypes
 
@@ -21,6 +21,9 @@ class Client:
         self.headers_done = 0
         self.debug = 0
 
+    def getuid(self):
+        return self.db.user.lookup(self.user)
+
     def header(self, headers={'Content-Type':'text/html'}):
         if not headers.has_key('Content-Type'):
             headers['Content-Type'] = 'text/html'
@@ -226,7 +229,7 @@ class Client:
                         props[key] = value
                 cl.set(self.nodeid, **props)
 
-                self._post_editnode(self.nodeid)
+                self._post_editnode(self.nodeid, changed)
                 # and some nice feedback for the user
                 message = '%s edited ok'%', '.join(changed)
             except:
@@ -317,7 +320,7 @@ class Client:
             props[key] = value
         return cl.create(**props)
 
-    def _post_editnode(self, nid):
+    def _post_editnode(self, nid, changes=None):
         ''' do the linking and message sending part of the node creation
         '''
         cn = self.classname
@@ -344,26 +347,57 @@ class Client:
                     link = self.db.classes[link]
                     link.set(nodeid, **{property: nid})
 
-        # if this item has messages, 
-        if (cl.getprops().has_key('messages') and
-                cl.getprops()['messages'].isMultilinkType and
-                cl.getprops()['messages'].classname == 'msg'):
+        # see if we want to send a message to the nosy list...
+        props = cl.getprops()
+        # don't do the message thing if there's no nosy list, or the editor
+        # of the node is the only person on the nosy list - they're already
+        # aware of the change.
+        nosy = 0
+        if props.has_key('nosy'):
+            nosy = cl.get(nid, 'nosy')
+            uid = self.getuid()
+            if len(nosy) == 1 and uid in nosy:
+                nosy = 0
+        if (nosy and props.has_key('messages') and
+                props['messages'].isMultilinkType and
+                props['messages'].classname == 'msg'):
+
+            # handle the note
+            note = None
+            if self.form.has_key('__note'):
+                note = self.form['__note']
+            if note is not None and note.value:
+                note = note.value
+                if '\n' in note:
+                    summary = re.split(r'\n\r?', note)[0]
+                else:
+                    summary = note
+                m = ['%s\n'%note]
+            else:
+                summary = 'This %s has been edited through the web.\n'%cn
+                m = [summary]
+
             # generate an edit message - nosyreactor will send it
-            m = []
-            for name, prop in cl.getprops().items():
-                value = cl.get(nid, name)
+            first = 1
+            for name, prop in props.items():
+                if changes is not None and name not in changes: continue
+                if first:
+                    m.append('\n-------')
+                    first = 0
+                value = cl.get(nid, name, None)
                 if prop.isLinkType:
                     link = self.db.classes[prop.classname]
-                    key = link.getkey()
+                    key = link.labelprop(default_to_id=1)
                     if value is not None and key:
                         value = link.get(value, key)
                     else:
                         value = '-'
                 elif prop.isMultilinkType:
+                    if value is None: value = []
                     l = []
                     link = self.db.classes[prop.classname]
+                    key = link.labelprop(default_to_id=1)
                     for entry in value:
-                        key = link.getkey()
                         if key:
                             l.append(link.get(entry, link.getkey()))
                         else:
@@ -371,25 +405,11 @@ class Client:
                     value = ', '.join(l)
                 m.append('%s: %s'%(name, value))
 
-            # handle the note
-            note = None
-            if self.form.has_key('__note'):
-                note = self.form['__note']
-            if note is not None and note.value:
-                note = note.value
-                if '\n' in note:
-                    summary = re.split(r'\n\r?', note)[0]
-                else:
-                    summary = note
-                m.append('\n%s\n'%note)
-            else:
-                summary = 'This %s has been created through the web.'%cn
-                m.append('\n%s\s'%summary)
-
             # now create the message
             content = '\n'.join(m)
-            message_id = self.db.msg.create(author='1', recipients=[],
-                date=date.Date('.'), summary=summary, content=content)
+            message_id = self.db.msg.create(author=self.getuid(),
+                recipients=[], date=date.Date('.'), summary=summary,
+                content=content)
             messages = cl.get(nid, 'messages')
             messages.append(message_id)
             props = {'messages': messages}
@@ -519,6 +539,19 @@ class Client:
 
 #
 # $Log: not supported by cvs2svn $
+# Revision 1.16  2001/08/02 05:55:25  richard
+# Web edit messages aren't sent to the person who did the edit any more. No
+# message is generated if they are the only person on the nosy list.
+#
+# Revision 1.15  2001/08/02 00:34:10  richard
+# bleah syntax error
+#
+# Revision 1.14  2001/08/02 00:26:16  richard
+# Changed the order of the information in the message generated by web edits.
+#
+# Revision 1.13  2001/07/30 08:12:17  richard
+# Added time logging and file uploading to the templates.
+#
 # Revision 1.12  2001/07/30 06:26:31  richard
 # Added some documentation on how the newblah works.
 #