Author: robin.munn
Date: Mon Mar 21 14:19:08 2005
New Revision: 47

Modified:
   trunk/mailman/src/mailman/database/schema.py
   trunk/mailman/src/mailman/database/tests/test_attribute.py
Log:
Added test and logic to lookup attribute values for the domain
when no attribute values found for mailing list.


Modified: trunk/mailman/src/mailman/database/schema.py
==============================================================================
--- trunk/mailman/src/mailman/database/schema.py        (original)
+++ trunk/mailman/src/mailman/database/schema.py        Mon Mar 21 14:19:08 2005
@@ -241,34 +241,43 @@
     name            = UnicodeCol(alternateID=True)
     groups          = RelatedJoin('AttributeGroup')
 
-    def getValue(self, attribute_name):
+    def get_value(self, attribute_name):
         """
         Returns the value corresponding to a given attribute, as a string.
 
         Returns None if no value can be found. (This will happen, for example,
         if the attribute name is misspelled).
+        
+        Lookup on attribute_name is case-insensitive.
 
         Possible ideas for later improvements: convert the string to the
         appropriate type.
         """
-        foundValue = None
+        result = None
         for group in self.groups:
             for value in group.values:
                 if attribute_name.lower() == value.name.lower():
-                    foundValue = value.value
+                    result = value.value
                     break
-            if foundValue is not None:
+            if result is not None:
                 break
-        if foundValue is not None:
-            return foundValue
-        else:
+
+        # check for values associated with domain
+        ld = self.list_domain()
+        if result is None and ld:
+            result = ListStyle.byName(ld).get_value(attribute_name)
+
+        # still nothing found, lookup "glabal" default for attribute
+        if result is None:
             attr = Attribute.byName(attribute_name)
             if attr is None:
-                return None
+                result = None
             else:
-                return attr.default_value
+                result = attr.default_value
+
+        return result
 
-    def getAttributes(self):
+    def get_attributes(self):
         """
         Returns all attributes and their values, as a dict.
         """
@@ -283,6 +292,19 @@
         # We're done!
         return result
 
+    def list_domain(self):
+        """
+        Return domain if this list style is for a mailing list, empty string
+        otherwise.
+
+        For example, if this ListStyle is for [EMAIL PROTECTED], this 
+        will return "lists.com"
+        """
+        try:
+            domain = self.name.split("@", 1)[1]
+        except IndexError:
+            domain = ""
+        return domain
 
 # XXX For performance reasons, because these tables are so normalized, we
 # could generate a lookup table which will only change when an attribute has

Modified: trunk/mailman/src/mailman/database/tests/test_attribute.py
==============================================================================
--- trunk/mailman/src/mailman/database/tests/test_attribute.py  (original)
+++ trunk/mailman/src/mailman/database/tests/test_attribute.py  Mon Mar 21 
14:19:08 2005
@@ -36,7 +36,7 @@
         style = schema.ListStyle(name='no_archive')
         style.addAttributeGroup(group)
         # group.addStyle(style)  # SQLObject automagically does this one
-        fetched_value = style.getValue('enable_archives')
+        fetched_value = style.get_value('enable_archives')
         eq(value.value, fetched_value)
 
     def test_default_when_no_value_given(self):
@@ -47,7 +47,7 @@
         group = schema.AttributeGroup(collection_name='archive_options')
         style = schema.ListStyle(name='yes_archive')
         style.addAttributeGroup(group)
-        fetched_value = style.getValue('enable_archives')
+        fetched_value = style.get_value('enable_archives')
         eq(fetched_value, attr.default_value)
 
     def test_default_when_no_value_given_and_no_groups(self):
@@ -56,7 +56,7 @@
                                 type='BOOL',
                                 default_value='True')
         style = schema.ListStyle(name='yes_archive')
-        fetched_value = style.getValue('enable_archives')
+        fetched_value = style.get_value('enable_archives')
         eq(fetched_value, attr.default_value)
 
     def test_get_all_attributes(self):
@@ -76,11 +76,27 @@
         style = schema.ListStyle(name='no_archive')
         style.addAttributeGroup(group)
         # group.addStyle(style)  # SQLObject automagically does this one
-        fetched_attrs = style.getAttributes()
+        fetched_attrs = style.get_attributes()
         eq(len(fetched_attrs), 2)
         eq(fetched_attrs[attr1.name], value1.value)
         eq(fetched_attrs[attr2.name], attr2.default_value)
     
+    def test_default_when_domain_but_no_list(self):
+        eq = self.assertEqual
+        attr = schema.Attribute(name='enable_archives',
+                                type='BOOL',
+                                default_value='True')
+        group = schema.AttributeGroup(collection_name='archive_options')
+        value1 = schema.AttributeValue(name='enable_archives',
+                                       group=group,
+                                       value='False',
+                                       policy='BASIC')
+        domain_style = schema.ListStyle(name='lists.com')
+        domain_style.addAttributeGroup(group)
+        list_style = schema.ListStyle(name='[EMAIL PROTECTED]')
+        fetched_value = list_style.get_value('enable_archives')
+        eq(fetched_value, 'False')
+
 
 
 def test_suite():
_______________________________________________
Mailman-checkins mailing list
[email protected]
Unsubscribe: 
http://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to