2 # Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
4 # This file is part of SiteCorePy.
6 # SiteCorePy is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by the
8 # Free Software Foundation, either version 2 of the License, or (at your
9 # option) any later version.
11 # SiteCorePy is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with SiteCorePy. If not, see <http://www.gnu.org/licenses/>.
19 """Move Professors from YAML -> Sitecore.
21 Professors will be created in:
22 Content -> Drexel -> ? -> physics -> ?
27 from selenium.common.exceptions import NoSuchElementException
30 from .. import SiteCoreConnection
31 from . import Name, Graduation, Contact, Bio, Professor
34 class ProfessorAdder (object):
35 """See doc/faculty.txt for Drexel's field/format policy.
37 def __init__(self, sitecore_connection):
38 self.s = sitecore_connection
41 #self.s.expand_nav_section('sitecore')
42 #self.s.expand_nav_section('Content')
43 self.s.expand_nav_section('Home')
44 for i in range(5): # 'physics' takes a while to load
46 self.s.expand_nav_section('physics')
47 except NoSuchElementException, e:
48 time.sleep(self.s.wait_time)
49 self.s.expand_nav_section('contact')
50 self.s.expand_nav_section('facultyDirectory')
52 def __call__(self, prof):
53 name = '%s %s' % (prof.name.first_middle, prof.name.last)
54 self.create_prof_page(name)
55 self.lock_section(name)
57 ('Degrees:', prof.degrees()),
58 ('College:', prof.colleges()),
59 ('Program:', prof.program()),
60 ('Office:', prof.contact.office),
61 ('Specialization:', prof.bio.specialization),
62 ('Research Interests:', ''),
63 ('Personal Site:', prof.sites()),
64 ('Title:', prof.title),
65 ('First Name:', prof.name.first_middle),
66 ('Last Name:', prof.name.last),
67 ('Bio:', '<p>\n%s\n%</p>'+prof.bio.profile.replace(
68 '\n', '\n</p>\n<p>\n')),
69 ('Headshot:', ('/Images/physics/headshots/%s'
70 % name.lower().replace('.','').replace(' ','_'))),
71 ('Email:', prof.contact.email),
72 ('Phone:', prof.contact.phone),
73 ('Fax:', prof.lab_contact()),
74 ('Page Title - This shows in the tab and title bar of the brower -- Google rates it highly:', name),
75 ("Menu Title - This shows in the menus and navigation blocks -- it's usually a shorted version of the page title:", name),
76 ("Breadcrumb Title - This shows in the breadcrumb trail -- it's usually a very short version of the page title:", name),
77 ("See Also title - Other items that refer to this one will use this text:", name),
79 for field_name,value in settings:
82 granddad,field = s.find_field(field_name)
84 field.send_keys(value)
85 #granddad,field = s.find_field('Headshot:')
86 #granddad.find_element_by_link_text('Properties')
87 # TODO, set width/height
88 s.publish_section('Added/updated Prof. %s' % prof.name.last)
90 def create_prof_page(self, name):
91 self.s.open_nav_section(name)
93 self.s.open_nav_section('Copy of Shyamalendu Bose')
94 old_windows = self.s.w.get_window_handles()
95 self.s.w.find_element_by_link_text('Copy To').click()
96 time.sleep(self.s.wait_time)
97 windows = self.s.w.get_window_handles()
98 current_window = self.s.w.get_current_window_handle()
99 popup = [w for w in windows if w not in old_windows][0]
100 if current_window != popup:
101 self.s.logger.info('handling copy popup %s (from %s, old %s)'
102 % (popup, windows, current_window))
103 self.s.w.switch_to_window(popup)
104 name = self.s.w.find_element_by_id('Filename')
107 '/sitecore/content/Home/physics/contact/facultyDirectory/%s'
109 self.s.w.find_element_by_id('OK').click()
110 time.sleep(self.s.wait_time)
111 current_window = self.s.w.get_current_window_handle()
112 self.s.logger.info('handled copy popup %s, back to %s'
113 % (popup, current_window))
114 self.s.open_nav_section(name)
116 def lock_section(self, name):
118 self.s.lock_section()
119 except NoSuchElementException, e:
120 self.s.logger.info("can't lock %s (already locked?), skipping" % name)
125 usage = """%prog [options] PROF_FILE
127 Where PROF_FILE is a YAML file containing professor data.
129 Example setup before running:
130 Xvfb :99 > /dev/null 2>&1 &
132 java -jar selenium-server-1.0.2-SNAPSHOT-standalone.jar > /dev/null 2>&1 &
133 ./sc.py prof-import profs.yaml
135 p = optparse.OptionParser(usage)
136 p.add_option('-u', '--url', metavar='URL', dest='url',
137 help='set the website URL (%default)',
138 default='https://webedit.drexel.edu/sitecore/login')
139 p.add_option('-v', '--verbose', dest='verbose', action='count',
140 help='increment verbosity (%default)',
143 options,args = p.parse_args(argv[1:])
145 profs = yaml.load(open(prof_file, 'r'))
147 s = SiteCoreConnection(options.url, options.verbose)
151 add = ProfessorAdder(s)