From: W. Trevor King Date: Wed, 30 Jun 2010 15:30:15 +0000 (-0400) Subject: Initial attempt at prof/import.py data import X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=16d26d048607bf17aaac94180d98d6433503cdcf;p=sitecorepy.git Initial attempt at prof/import.py data import --- diff --git a/sitecore/prof/__init__.py b/sitecore/prof/__init__.py index 7b24e72..0995fac 100644 --- a/sitecore/prof/__init__.py +++ b/sitecore/prof/__init__.py @@ -106,10 +106,11 @@ class Graduation (AttributeHolder): fields = ['college', 'field', 'title', 'year'] class Contact (AttributeHolder): - fields = ['office', 'email', 'website', 'phone', 'lab', 'lab_phone'] + fields = ['office', 'email', 'website', 'groupsite', + 'phone', 'lab', 'lab_phone'] class Bio (AttributeHolder): - fields = ['specialization', 'publications', 'profile', 'cv'] + fields = ['category', 'specialization', 'publications', 'profile', 'cv'] class Professor (AttributeHolder): fields = ['name', 'title', 'graduations', 'contact', 'bio'] @@ -147,3 +148,30 @@ class Professor (AttributeHolder): if m in degrees: degrees.remove(m) return '|'.join(degrees) + + def colleges(self): + titles = self.degrees().split('|') + return '|'.join([g.college for g in self.graduations + if g.title in titles]) + + def program(self): + "Sub-field(s)" + if self.contact.group_site == None: + return 'Physics' + #TODO: group to sub-field logic + + def sites(self): + if self.contact.groupsite == None: + return ('%s' + % (self.contact.website, self.contact.website)) + return ('Group Website: %s|Personal Website: %s' + % (self.contact.groupsite, self.contact.groupsite, + self.contact.website, self.contact.website)) + + def lab_contact(self): + "Lab Name, Lab Phone" + if self.contact.lab != None: + assert self.contact.lab_phone != None, unicode(self.name) + return '%s, %s' % (self.contact.lab, self.contact.lab_phone) + assert self.contact.lab_phone == None, unicode(self.name) + return None diff --git a/sitecore/prof/export_mysql.py b/sitecore/prof/export_mysql.py index 152eb95..e484fc8 100644 --- a/sitecore/prof/export_mysql.py +++ b/sitecore/prof/export_mysql.py @@ -172,7 +172,7 @@ Where the relevant categories are ) p.title = prof['position'] if prof['position1'] != None: - p.title += ', %s' % prof['position1'] + p.title += '|%s' % prof['position1'] p.graduations = [] degrees = [] if prof['degrees'] != None: @@ -195,12 +195,14 @@ Where the relevant categories are office=prof['office'], email=prof['email'], website=prof['personalpage'], + groupsite=prof['grouppage'], phone=prof['phone'], lab=prof['lab'], lab_phone=prof['labphone'], ) p.bio = Bio( - specialization=prof['research'], # prof['grouppage'] + role=prof['category'], + specialization=prof['research'], publications=None, profile=prof['profile'], cv=None, diff --git a/sitecore/prof/import.py b/sitecore/prof/import.py index 6faefcb..77afc41 100644 --- a/sitecore/prof/import.py +++ b/sitecore/prof/import.py @@ -50,11 +50,44 @@ class ProfessorAdder (object): self.s.expand_nav_section('facultyDirectory') def __call__(self, prof): - self.create_prof_page(prof) - TODO - - def create_prof_page(self, prof): name = '%s %s' % (prof.name.first_middle, prof.name.last) + self.create_prof_page(name) + self.lock_section() + settings = [ + ('Degrees:', prof.degrees()), + ('College:', prof.colleges()), + ('Program:', prof.program()), + ('Office:', prof.contact.office), + ('Specialization:', prof.bio.specialization), + ('Research Interests:', ''), + ('Personal Site:', prof.sites()), + ('Title:', prof.title), + ('First Name:', prof.name.first_middle), + ('Last Name:', prof.name.last), + ('Bio:', '

\n%s\n%

'+prof.bio.profile.replace( + '\n', '\n

\n

\n')), + ('Headshot:', ('/Images/physics/headshots/%s' + % name.lower().replace('.','').replace(' ','_'))), + ('Email:', prof.contact.email), + ('Phone:', prof.contact.phone), + ('Fax:', prof.lab_contact()), + ('Page Title - This shows in the tab and title bar of the brower -- Google rates it highly:', name), + ("Menu Title - This shows in the menus and navigation blocks -- it's usually a shorted version of the page title:", name), + ("Breadcrumb Title - This shows in the breadcrumb trail -- it's usually a very short version of the page title:", name), + ("See Also title - Other items that refer to this one will use this text:", name), + ] + for field_name,value in settings: + if value == None: + value = '' + granddad,field = s.find_field(field_name) + field.clear() + field.send_keys(value) + #granddad,field = s.find_field('Headshot:') + #granddad.find_element_by_link_text('Properties') + # TODO, set width/height + s.publish_section('Added/updated Prof. %s' % prof.name.last) + + def create_prof_page(self, name): self.s.open_nav_section(name) return self.s.open_nav_section('Copy of Shyamalendu Bose') @@ -80,6 +113,12 @@ class ProfessorAdder (object): % (popup, current_window)) self.s.open_nav_section(name) + def lock_section(self): + try: + self.s.lock_section() + except NoSuchElementException, e: + self.s.logger.info("can't lock %s (already locked?), skipping" % raw_name) + def main(argv): import optparse