[Zope-CVS] CVS: Products/NotifyList - TODO.txt:1.1 refresh.txt:1.1 NotifyList.py:1.2 __init__.py:1.2

Shane Hathaway shane@cvs.zope.org
Wed, 16 Jan 2002 17:28:51 -0500


Update of /cvs-repository/Products/NotifyList
In directory cvs.zope.org:/tmp/cvs-serv30731

Modified Files:
	NotifyList.py __init__.py 
Added Files:
	TODO.txt refresh.txt 
Log Message:
Notify list manipulation is now 90% functional.


=== Added File Products/NotifyList/TODO.txt ===
Known issues:

- You can't copy/paste a notify database.


=== Added File Products/NotifyList/refresh.txt ===


=== Products/NotifyList/NotifyList.py 1.1.1.1 => 1.2 ===
+#
+# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
+# 
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE
+# 
+##############################################################################
 
 import os
 
@@ -7,11 +19,18 @@
 from Acquisition import aq_inner, aq_parent
 from OFS.SimpleItem import SimpleItem
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
+from AccessControl import ClassSecurityInfo
 
 _www = os.path.join(os.path.dirname(__file__), 'www')
 
+from Products.CMFCore.DirectoryView import registerDirectory
+registerDirectory('skins', globals())
 
-class EmailInfo (Persistent):
+
+ManageNotifyList = 'Manage Notification Lists'
+
+
+class EmailRecord (Persistent):
     is_group = 0
 
     name = ''
@@ -19,7 +38,7 @@
 
 
 
-class GroupInfo (Persistent):
+class GroupRecord (Persistent):
     is_group = 1
 
     name = ''
@@ -29,28 +48,38 @@
 
 class NotifyDatabase (SimpleItem):
     meta_type = 'Notify Database'
+
     id = 'notify_db'
 
+    security = ClassSecurityInfo()
+
     def __init__(self):
-        # { id -> EmailInfo or GroupInfo }        
-        self.contents = PersistentMapping()
+        # { id -> EmailRecord or GroupRecord }        
+        self._contents = PersistentMapping()
 
-    def getInfoById(self, id):
-        return self.contents.get(id, None)
+    security.declarePrivate('getRecordById')
+    def getRecordById(self, id):
+        return self._contents.get(id, None)
 
+    security.declarePrivate('listAllIds')
     def listAllIds(self):
-        return self.contents.keys()
+        return self._contents.keys()
 
-    def addInfo(self, ob):
-        ids = self.contents.keys()
+    security.declarePrivate('addRecord')
+    def addRecord(self, ob):
+        ids = self._contents.keys()
         if ids:
             ids.sort()
             id = '%03d' % (int(ids[-1]) + 1)
         else:
             id = '001'
-        self.contents[id] = ob
+        self._contents[id] = ob
         return id
 
+    security.declarePrivate('deleteRecord')
+    def deleteRecord(self, id):
+        del self._contents[id]
+
 Globals.InitializeClass(NotifyDatabase)
 
 
@@ -58,9 +87,12 @@
 class NotifyList (SimpleItem):
     meta_type = 'Notify List'
 
+    security = ClassSecurityInfo()
+
     db_id = NotifyDatabase.id
     ids = ()
 
+    security.declarePrivate('getDatabase')
     def getDatabase(self):
         parent = aq_parent(aq_inner(self))
         return getattr(parent, self.db_id)
@@ -69,52 +101,73 @@
         db = self.getDatabase()
         lst = []
         for id in ids:
-            info = db.getInfoById(id)
-            if info.is_group:
-                lst.append((info.name.lower(), info.name, id, 1))
+            record = db.getRecordById(id)
+            if record is None:
+                continue
+            if record.is_group:
+                lst.append(('0' + record.name.lower(), record.name, id, 1))
             else:
-                if info.email:
-                    name_email = '%s <%s>' % (info.name, info.email)
+                if record.email:
+                    desc = '%s <%s>' % (record.name, record.email)
                 else:
-                    name_email = info.name
-                lst.append((name_email.lower(), name_email, id, 0))
+                    desc = record.name
+                lst.append(('1' + desc.lower(), desc, id, 0))
         lst.sort()
-        res = map(lambda (sort_key, name_email, id, is_group): {
-            'id': id, 'name_email': name_email, 'is_group': is_group}, lst)
+        res = map(lambda (sort_key, desc, id, is_group): {
+            'id': id, 'description': desc, 'is_group': is_group}, lst)
         return res
 
+    security.declarePublic(ManageNotifyList, 'listContents')
     def listContents(self):
-        """Returns a list of dictionaries containing id, name_email, is_group
+        """Returns a list of dictionaries containing id, description, is_group
         """
         return self._idsToMappings(self.ids)
 
+    security.declarePublic(ManageNotifyList, 'listGroupContents')
     def listGroupContents(self, group_id):
+        """Returns a list of dictionaries similar to listContents()
+        """
         db = self.getDatabase()
-        info = db.getInfoById(group_id)
-        if info is not None and info.is_group:
-            return self._idsToMappings(info.ids)
-
-    def listAllEmailsAndGroups(self):
+        record = db.getRecordById(group_id)
+        if record is not None and record.is_group:
+            return self._idsToMappings(record.ids)
+
+    security.declarePublic(ManageNotifyList, 'listAllEmailsAndGroups')
+    def listAllEmailsAndGroups(self, exclude_my_ids=0):
+        """Returns a list of dictionaries similar to listContents()
+        """
         db = self.getDatabase()
         ids = db.listAllIds()
+        if exclude_my_ids:
+            ids = filter(lambda id, exclude_ids=self.ids:
+                         id not in exclude_ids, ids)
         return self._idsToMappings(ids)
         
     def _addIds(self, container, ids):
+        if not ids:
+            # No changes.
+            return
         new_ids = {}
         for id in container.ids:
             new_ids[id] = 1
+        available_ids = self.getDatabase().listAllIds()
         for id in ids:
-            new_ids[id] = 1
+            if id in available_ids:
+                new_ids[id] = 1
+            else:
+                raise ValueError, 'Id %s not found.' % id
         container.ids = tuple(new_ids.keys())
 
+    security.declarePublic(ManageNotifyList, 'addToList')
     def addToList(self, ids):
         self._addIds(self, ids)
 
+    security.declarePublic(ManageNotifyList, 'addToGroupList')
     def addToGroupList(self, group_id, ids):
         db = self.getDatabase()
-        info = db.getInfoById(group_id)
-        if info is not None and info.is_group:
-            self._addIds(info, ids)
+        record = db.getRecordById(group_id)
+        if record is not None and record.is_group:
+            self._addIds(record, ids)
 
     def _removeIds(self, container, ids):
         new_ids = {}
@@ -125,42 +178,101 @@
                 del new_ids[id]
         container.ids = tuple(new_ids.keys())
 
+    security.declarePublic(ManageNotifyList, 'removeFromList')
     def removeFromList(self, ids):
         self._removeIds(self, ids)
         
+    security.declarePublic(ManageNotifyList, 'removeFromGroupList')
     def removeFromGroupList(self, group_id, ids):
         db = self.getDatabase()
-        info = db.getInfoById(group_id)
-        if info is not None and info.is_group:
-            self._removeIds(info, ids)
+        record = db.getRecordById(group_id)
+        if record is not None and record.is_group:
+            self._removeIds(record, ids)
 
+    security.declarePublic(ManageNotifyList, 'addEmail')
     def addEmail(self, name, email):
         """Returns the id of the new email.
         """
         db = self.getDatabase()
-        ei = EmailInfo()
+        ei = EmailRecord()
         ei.name = str(name)
         ei.email = str(email)
-        id = db.addInfo(ei)
+        id = db.addRecord(ei)
         return id
 
+    security.declarePublic(ManageNotifyList, 'addGroup')
     def addGroup(self, name):
         """Returns the id of the new group.
         """
         db = self.getDatabase()
-        ei = GroupInfo()
+        ei = GroupRecord()
         ei.name = str(name)
-        id = db.addInfo(ei)
+        id = db.addRecord(ei)
         return id
 
+    security.declarePublic(ManageNotifyList, 'getGroupName')
     def getGroupName(self, id):
         """Returns the name of a group.
         """
         db = self.getDatabase()
-        info = db.getInfoById(id)
-        if info is None or not info.is_group:
-            raise KeyError, 'Group not found'
-        return info.name
+        record = db.getRecordById(id)
+        if record is None or not record.is_group:
+            raise KeyError, 'Group %s not found' % id
+        return record.name
+
+    security.declarePublic(ManageNotifyList, 'getEmailInfo')
+    def getEmailInfo(self, id):
+        """Returns a mapping containing name and email.
+        """
+        db = self.getDatabase()
+        record = db.getRecordById(id)
+        if record is None or record.is_group:
+            raise KeyError, 'Record %s not found or wrong type' % id
+        return {'name': record.name, 'email': record.email}
+
+    security.declarePublic(ManageNotifyList, 'changeEmail')
+    def changeEmail(self, id, name, email):
+        """Changes a name and email address.
+        """
+        db = self.getDatabase()
+        record = db.getRecordById(id)
+        if record is None or record.is_group:
+            raise KeyError, 'Record %s not found or wrong type' % id
+        record.name = str(name)
+        record.email = str(email)
+
+    security.declarePublic(ManageNotifyList, 'changeGroup')
+    def changeGroup(self, id, name):
+        """Changes a name and email address.
+        """
+        db = self.getDatabase()
+        record = db.getRecordById(id)
+        if record is None or not record.is_group:
+            raise KeyError, 'Record %s not found or wrong type' % id
+        record.name = str(name)
+
+    security.declarePublic(ManageNotifyList, 'deleteRecord')
+    def deleteRecord(self, id):
+        """Deletes an email or group record.
+        """
+        db = self.getDatabase()
+        db.deleteRecord(id)
+
+    security.declarePublic(ManageNotifyList, 'getListAsText')
+    def getListAsText(self):
+        """
+        """
+
+    security.declarePublic(ManageNotifyList, 'setListAsText')
+    def setListAsText(self, text):
+        """
+        """
+
+    security.declarePublic(ManageNotifyList, 'getEmailsForNotification')
+    def getEmailsForNotification(self):
+        """
+        """
+
 
 Globals.InitializeClass(NotifyList)
 


=== Products/NotifyList/__init__.py 1.1.1.1 => 1.2 ===
+#
+# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
+# 
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE
+# 
+##############################################################################
 """NotifyList product
 """