From: W. Trevor King Date: Sun, 27 Jun 2010 12:26:18 +0000 (-0400) Subject: Added Professor.degrees() X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d97f28c333c2e7418e9f0f976190f74e95183c7c;p=sitecorepy.git Added Professor.degrees() --- diff --git a/sitecore/prof/__init__.py b/sitecore/prof/__init__.py index d6011fb..d6d424a 100644 --- a/sitecore/prof/__init__.py +++ b/sitecore/prof/__init__.py @@ -109,4 +109,36 @@ class Bio (AttributeHolder): class Professor (AttributeHolder): fields = ['name', 'title', 'graduations', 'contact', 'bio'] -# LocalWords: SiteCorePy + def degrees(self): + if self.graduations in [None, []]: + return None + degrees = [g.title for g in self.graduations] + masks = { + 'M.S.':['B.S.', 'B.A.', 'B.M.'], + 'Ph.D.':['M.S.', 'M.A.', 'M.Phil.'], + } + # Princeton uses 'S.M.', 'A.B.', ... instead of 'M.S.', 'B.A.', ... + def princeton_title(title): + if m[:2] in ['B.', 'M.']: + fields = title.split('.') + assert (len(fields) == 3 and fields[2] == ''), \ + '%s -> %s\n%s' % (title, fields, self.name) + return '.'.join([fields[1], fields[0]] + fields[2:]) + return title + for title,masked in masks.items(): + ms = list(masked) + for m in ms: + pt = princeton_title(m) + if pt != m and pt not in masked: + masked.append(pt) + pt = princeton_title(title) + if pt not in masks: + masks[pt] = masked + masks['Ph.D.'].extend(masks['M.S.']) + masks['M.A'] = masks['M.Phil'] = masks['M.S.'] + for title,masked in masks.items(): + if title in degrees: + for m in masked: + if m in degrees: + degrees.remove(m) + return '|'.join(degrees)