Author: robin.munn
Date: Mon Mar 21 13:46:08 2005
New Revision: 46
Modified:
trunk/mailman/src/mailman/database/schema.py
trunk/mailman/src/mailman/database/tests/test_attribute.py
Log:
New function: ListStyle.getAllAttributes(). Fetches all attributes as a dict;
if any are not present in a style's attribute groups, their default value
is used.
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 13:46:08 2005
@@ -268,6 +268,21 @@
else:
return attr.default_value
+ def getAttributes(self):
+ """
+ Returns all attributes and their values, as a dict.
+ """
+ result = {}
+ # First set defaults
+ for attr in Attribute.select():
+ result[attr.name] = attr.default_value
+ # Now update with the values from our style
+ for group in self.groups:
+ for value in group.values:
+ result[value.name] = value.value
+ # We're done!
+ return result
+
# 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
13:46:08 2005
@@ -58,6 +58,28 @@
style = schema.ListStyle(name='yes_archive')
fetched_value = style.getValue('enable_archives')
eq(fetched_value, attr.default_value)
+
+ def test_get_all_attributes(self):
+ eq = self.assertEqual
+ attr1 = schema.Attribute(name='enable_archives',
+ type='BOOL',
+ default_value='True')
+ attr2 = schema.Attribute(name='max_hold',
+ type='NUMBER',
+ default_value='10')
+ group = schema.AttributeGroup(collection_name='archive_options')
+ value1 = schema.AttributeValue(name='enable_archives',
+ group=group,
+ value='False',
+ policy='BASIC')
+ # No value2 -- we want to get its default value
+ style = schema.ListStyle(name='no_archive')
+ style.addAttributeGroup(group)
+ # group.addStyle(style) # SQLObject automagically does this one
+ fetched_attrs = style.getAttributes()
+ eq(len(fetched_attrs), 2)
+ eq(fetched_attrs[attr1.name], value1.value)
+ eq(fetched_attrs[attr2.name], attr2.default_value)
_______________________________________________
Mailman-checkins mailing list
[email protected]
Unsubscribe:
http://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org