Added string output methods to AttributeHolder.
authorW. Trevor King <wking@drexel.edu>
Sat, 26 Jun 2010 21:11:50 +0000 (17:11 -0400)
committerW. Trevor King <wking@drexel.edu>
Sat, 26 Jun 2010 21:11:50 +0000 (17:11 -0400)
sitecore/prof/__init__.py

index 32bd67959b18197c6213a598a367679c5a009333..d8c66624f163ba06b2172083ab39bb3a7e5eec97 100644 (file)
@@ -67,6 +67,26 @@ class AttributeHolder (object):
             assert field in self.fields, '%s not in %s' % (field, self.fields)
             setattr(self, field, value)
 
+    def __str__(self):
+        return self.__unicode__()
+
+    def __repr__(self):
+        return self.__unicode__()
+
+    def __unicode__(self):
+        lines = ['%s:' % self.__class__.__name__]
+        for field in self.fields:
+            value = getattr(self, field)
+            if value == None:
+                continue
+            value_lines = unicode(value).splitlines()
+            if isinstance(value, AttributeHolder):
+                prefix = '  '
+            else:
+                prefix = '  %s: ' % field
+            lines.extend(['%s%s' % (prefix, L) for L in value_lines])
+        return u'\n'.join(lines)
+
 
 class Name (AttributeHolder):
     fields = ['first_middle', 'last']