[Zope3-checkins] CVS: Products3/z3checkins - configure.zcml:1.14 folder.py:1.3 message.py:1.25

Gintautas Miliauskas gintas at pov.lt
Tue Feb 10 11:20:59 EST 2004


Update of /cvs-repository/Products3/z3checkins
In directory cvs.zope.org:/tmp/cvs-serv18601

Modified Files:
	configure.zcml folder.py message.py 
Log Message:
* duplicate messages are now handled (the new one is ignored)
* added sizing adapter for nice sorting
* added unit tests for name choosing and sizing adapters
* added a view for messages


=== Products3/z3checkins/configure.zcml 1.13 => 1.14 ===
--- Products3/z3checkins/configure.zcml:1.13	Tue Feb 10 09:23:27 2004
+++ Products3/z3checkins/configure.zcml	Tue Feb 10 11:20:28 2004
@@ -57,6 +57,12 @@
            permission="zope.View"
            provides="zope.app.interfaces.container.INameChooser" />
 
+  <adapter for=".interfaces.IMessage"
+           factory=".folder.MessageSized"
+           permission="zope.View"
+           provides="zope.app.interfaces.size.ISized" />
+
+
   <utility factory=".message.CheckinMessageParser"
            permission="zope.View"
            provides=".interfaces.IMessageParser" />
@@ -197,6 +203,7 @@
     name="index.html"
     template="message.pt"
     class=".message.CheckinMessageView"
+    menu="zmi_views" title="Preview"
     permission="zope.View" />
 
   <browser:page


=== Products3/z3checkins/folder.py 1.2 => 1.3 ===
--- Products3/z3checkins/folder.py:1.2	Tue Feb 10 09:23:27 2004
+++ Products3/z3checkins/folder.py	Tue Feb 10 11:20:28 2004
@@ -10,6 +10,7 @@
 from zope.app.container.btree import BTreeContainer
 from zope.app.interfaces.container import INameChooser
 from zope.app.interfaces.container import IContainerNamesContainer
+from zope.app.interfaces.size import ISized
 from interfaces import ICheckinsFolder
 
 class CheckinsFolder(BTreeContainer):
@@ -32,3 +33,20 @@
     def checkName(self, name, message):
         return name == message.message_id
 
+
+class MessageSized:
+    """An adapter to calculate size of a message."""
+    implements(ISized)
+
+    def __init__(self, message):
+        self._message = message
+
+    def sizeForSorting(self):
+        return len(self._message.full_text)
+
+    def sizeForDisplay(self):
+        bytes = len(self._message.full_text)
+        if bytes < 1024:
+            return u'%d bytes' % bytes
+        else:
+            return u'%d KB' % (bytes / 1024)


=== Products3/z3checkins/message.py 1.24 => 1.25 ===
--- Products3/z3checkins/message.py:1.24	Tue Feb 10 09:23:27 2004
+++ Products3/z3checkins/message.py	Tue Feb 10 11:20:28 2004
@@ -28,6 +28,7 @@
 from zope.publisher.browser import BrowserView
 from zope.app.pagetemplate import ViewPageTemplateFile
 from zope.app.interfaces.dublincore import IZopeDublinCore
+from zope.exceptions import DuplicationError
 
 from interfaces import IMessage, ICheckinMessage, IBookmark, IMessageContained
 from interfaces import IMessageUpload
@@ -330,7 +331,11 @@
             mbox = StringIO(msg_raw)
             messages = mailbox.PortableUnixMailbox(mbox, factory=parser.parse)
             for message in messages:
-                self.add(message)
+                try:
+                    self.add(message)
+                except DuplicationError:
+                    # leave the old mesage unchanged if a duplicate is found
+                    pass
         else:
             message = parser.parse(msg_raw)
             self.add(message)




More information about the Zope3-Checkins mailing list