From: W. Trevor King Date: Sat, 26 Jun 2010 21:37:04 +0000 (-0400) Subject: Added list-handling to AttributeHolder.__unicode__ X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=63618bfe355b20426dcffd0ce63ca845261a0364;p=sitecorepy.git Added list-handling to AttributeHolder.__unicode__ Also added some missing fields from the Drexel specs to the AttributeHolder subclasses. --- diff --git a/sitecore/prof/__init__.py b/sitecore/prof/__init__.py index d8c6662..c78899d 100644 --- a/sitecore/prof/__init__.py +++ b/sitecore/prof/__init__.py @@ -71,7 +71,7 @@ class AttributeHolder (object): return self.__unicode__() def __repr__(self): - return self.__unicode__() + return '<%s>' % self.__unicode__().replace('\n',';') def __unicode__(self): lines = ['%s:' % self.__class__.__name__] @@ -79,14 +79,20 @@ class AttributeHolder (object): value = getattr(self, field) if value == None: continue - value_lines = unicode(value).splitlines() - if isinstance(value, AttributeHolder): - prefix = ' ' + if isinstance(value, (tuple, list)): + for v in value: + lines.extend(self._format_value(field, v)) else: - prefix = ' %s: ' % field - lines.extend(['%s%s' % (prefix, L) for L in value_lines]) + lines.extend(self._format_value(field, value)) return u'\n'.join(lines) + def _format_value(self, field, value): + value_lines = unicode(value).splitlines() + if isinstance(value, AttributeHolder): + prefix = ' ' + else: + prefix = ' %s: ' % field + return ['%s%s' % (prefix, L) for L in value_lines] class Name (AttributeHolder): fields = ['first_middle', 'last'] @@ -95,10 +101,12 @@ class Graduation (AttributeHolder): fields = ['college', 'title', 'year'] class Contact (AttributeHolder): - fields = ['office', 'website', 'phone', 'lab', 'lab_phone'] + fields = ['office', 'email', 'website', 'phone', 'lab', 'lab_phone'] class Bio (AttributeHolder): fields = ['specialization', 'publications', 'profile', 'cv'] class Professor (AttributeHolder): - fields = ['name', 'graduations', 'contact', 'bio'] + fields = ['name', 'title', 'graduations', 'contact', 'bio'] + +# LocalWords: SiteCorePy