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']