Author: barry.warsaw
Date: Tue Mar 22 15:41:31 2005
New Revision: 61

Added:
   trunk/mailman/src/mailman/database/tests/test_languagetexts.py
Modified:
   trunk/mailman/src/mailman/database/schema.py
Log:
Rework the cachable language text stuff so that we can have multiple texts in
different languages.  Use inheritance to implement the autoresponse texts.
Added test cases.



Modified: trunk/mailman/src/mailman/database/schema.py
==============================================================================
--- trunk/mailman/src/mailman/database/schema.py        (original)
+++ trunk/mailman/src/mailman/database/schema.py        Tue Mar 22 15:41:31 2005
@@ -31,11 +31,12 @@
     'Attribute',
     'AttributeGroup',
     'AttributeValue',
-    'Autoresponse',
+    'AutoresponseText',
     'BounceInfo',
-    'CachedLanguageText',
     'Domain',
     'EmailAddress',
+    'LanguageText',
+    'LanguageTextCollection',
     'ListMemberPreferences',
     'ListStyle',
     'MailingList',
@@ -66,7 +67,7 @@
     name                = UnicodeCol(alternateID=True)
     # A longer, human readable description of the mailing list.  This can
     # contain HTML.
-    description         = ForeignKey('CachedLanguageText', default=None)
+    description         = ForeignKey('LanguageTextCollection', default=None)
     # List owners have all the rights (conferred to them by site and domain
     # owners) to modify the mailing list's attributes.
     owners              = ForeignKey('Roster')
@@ -81,9 +82,9 @@
     # The next three fields contain the autoresponse text used when a message
     # is sent to the list's posting address, the -owner address or the
     # -request robot address, respectively.
-    post_response       = ForeignKey('Autoresponse', default=None)
-    owner_response      = ForeignKey('Autoresponse', default=None)
-    request_response    = ForeignKey('Autoresponse', default=None)
+    post_response       = ForeignKey('LanguageTextCollection', default=None)
+    owner_response      = ForeignKey('LanguageTextCollection', default=None)
+    request_response    = ForeignKey('LanguageTextCollection', default=None)
     # Every message approved for posting to the list ends up in the archive
     # message collection.  This doesn't necessarily mean the message is
     # accessible from the archive.
@@ -355,17 +356,18 @@
 
 
 
-class Autoresponse(SQLObject):
+class LanguageTextCollection(SQLObject):
     _cacheValue     = False
-    # Autoresponses are those texts which are sent in response to a list
-    # posting, a -request message, or a message to the -owners.  Each
-    # autoresponse has a grace period, during which we will not resend the
-    # response text.  Response texts can be in any supported language
-    graceperiod     = IntCol(default=90*24*60*60) # seconds, FIXME
-    response_text   = ForeignKey('CachedLanguageText')
+    texts           = MultipleJoin('LanguageText', joinColumn='member_of_id')
+
+    def get_text(self, language):
+        for text in self.texts:
+            if text.for_language == language:
+                return text.text
+        return ''
 
 
-class CachedLanguageText(SQLObject):
+class LanguageText(InheritableSQLObject):
     _cacheValue     = False
     # This table represents any human readable text for a mailing list, such
     # as the welcome message or an autoresponse message..  Its purpose is
@@ -385,6 +387,17 @@
     last_cached     = DateTimeCol(default=None)
     cache_lifetime  = IntCol(default=60*60)  # seconds, FIXME
     text            = UnicodeCol(default=None)
+    # Pointer back to the collection
+    member_of       = ForeignKey('LanguageTextCollection')
+
+
+class AutoresponseText(LanguageText):
+    _cacheValue     = False
+    # Autoresponses are those texts which are sent in response to a list
+    # posting, a -request message, or a message to the -owners.  Each
+    # autoresponse has a grace period, during which we will not resend the
+    # response text.  Response texts can be in any supported language
+    graceperiod     = IntCol(default=90*24*60*60) # seconds, FIXME
 
 
 

Added: trunk/mailman/src/mailman/database/tests/test_languagetexts.py
==============================================================================
--- (empty file)
+++ trunk/mailman/src/mailman/database/tests/test_languagetexts.py      Tue Mar 
22 15:41:31 2005
@@ -0,0 +1,86 @@
+# Copyright (C) 2005 Barry A. Warsaw
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the Free
+# Software Foundation; either version 2 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+# Place - Suite 330, Boston, MA 02111-1307, USA.
+
+import email
+import email.Utils
+import datetime
+import unittest
+
+from mailman.database.schema import *
+from mailman.database.tests.base import DatabaseTest
+
+
+
+class TestLanguageTexts(DatabaseTest):
+    def setUp(self):
+        DatabaseTest.setUp(self)
+        self._collection = collection = LanguageTextCollection()
+        self._hello1 = LanguageText(for_language='en',
+                                    url='fake',
+                                    text='hello',
+                                    member_of=collection)
+        self._hello2 = LanguageText(for_language='de',
+                                    url='fake',
+                                    text='guten tag',
+                                    member_of=collection)
+        self._hello3 = LanguageText(for_language='fr',
+                                    url='fake',
+                                    text='bonjour',
+                                    member_of=collection)
+
+
+    def test_language_collection(self):
+        eq = self.assertEqual
+        eq(len(self._collection.texts), 3)
+        eq(self._collection.get_text('en'), 'hello')
+        eq(self._collection.get_text('de'), 'guten tag')
+        eq(self._collection.get_text('fr'), 'bonjour')
+        eq(self._collection.get_text('es'), '')
+
+    def test_mailing_list_description(self):
+        eq = self.assertEqual
+        owners = Roster()
+        moderators = Roster()
+        members = Roster()
+        # Create a mailing list domain
+        domain_admins = Roster()
+        domain = Domain(name='localhost',
+                        mailhost='localhost',
+                        admins=domain_admins)
+        # Create the required message collection
+        archives = MessageCollection()
+        owner_archives = MessageCollection()
+        # Finally!  Create the mailing list.
+        mlist = MailingList(name='[EMAIL PROTECTED]',
+                            owners=owners,
+                            moderators=moderators,
+                            members=members,
+                            domain=domain,
+                            archives=archives,
+                            owner_archives=owner_archives,
+                            description=self._collection,
+                            )
+        eq(mlist.description.get_text('en'), 'hello')
+        eq(mlist.description.get_text('de'), 'guten tag')
+        eq(mlist.description.get_text('fr'), 'bonjour')
+        eq(mlist.description.get_text('es'), '')
+
+
+
+def test_suite():
+    suite = unittest.TestSuite()
+    suite.addTest(unittest.makeSuite(TestLanguageTexts))
+    return suite
_______________________________________________
Mailman-checkins mailing list
[email protected]
Unsubscribe: 
http://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to