def test_instant_messengers(self): self.folder.invokeFactory("Person", "user1") user1 = self.folder["user1"] adapter = IContactInfo(user1) adapter.instant_messengers = [ {"category": "gtalk", "data": "*****@*****.**"}, {"category": "skype", "data": "*****@*****.**"}, ] self.assertEquals(len(adapter.instant_messengers), 2)
def demo_steps(context): """ Run steps to prepare a demo. """ if context.readDataFile('s17.employee-demo.txt') is None: return portal = context.getSite() portal.invokeFactory('Folder', 'employees') folder = portal['employees'] folder.title = 'Employees' pw = getToolByName(portal, 'portal_workflow') list_users = [{'name':'marcelo-santos', 'password':'******', 'number': '1', 'birthday': (1985, 2, 17)}, {'name':'marcelo-alves', 'password':'******', 'number': '2', 'birthday': (1983, 6, 01)}, {'name':'julia-alvarez', 'password':'******', 'number': '3', 'birthday': (1988, 10, 26)}, {'name':'juan-perez', 'password':'******', 'number': '4', 'birthday': (1981, 1, 15)}, {'name':'gustavo-roner', 'password':'******', 'number': '5', 'birthday': (1986, 2, 15)}] for user in list_users: create_user(user['name'], user['password'], portal) # Set behaviors to employee fti = queryUtility(IDexterityFTI, name='Employee') behaviors = fti.behaviors + \ tuple(['s17.person.behaviors.user.IPloneUser', 's17.person.behaviors.contact.IContactInfo']) fti.behaviors = tuple(behaviors) for user in list_users: employee = user['name'] fullname = employee.split('-') birthday = user['birthday'] image = os.path.join(os.path.dirname(__file__), 'profiles', 'demo', 'images', 'picture%s.png' % user['number']) data = getFile(image).read() folder.invokeFactory('Employee', employee, birthday=datetime.date(datetime(birthday[0], birthday[1], birthday[2])), picture=NamedImage(data), given_name=fullname[0].capitalize(), surname=fullname[1].capitalize(), gender=u'm', ) if (employee == 'julia-alvarez'): folder[employee].gender = 'f' p1_contact = IContactInfo(folder[employee]) p1_contact.emails = [{'category': u'work', 'data': u'*****@*****.**' % employee.replace('-', '.')}, {'category': u'home', 'data': u'*****@*****.**' % employee.replace('-', '.')}] p1_contact.instant_messengers = [{'category': u'skype', 'data': u'%s' % employee.replace('-', '_')}] p1_contact.telephones = [{'category': 'home', 'data': '+5511555.1213'}, {'category': 'work', 'data': '+5511316.9876'}] p1_ploneuser = IPloneUser(folder[employee]) p1_ploneuser.user_name = employee folder[employee].reindexObject() review_state = pw.getStatusOf(folder[employee], 'review_state') if not review_state == 'internally_published': pw.doActionFor(folder[employee], 'publish_internally') # publish folder. Folder must have intranet_workflow assigned. review_state = pw.getStatusOf(folder, 'review_state') folder_wchain = pw.getChainFor(folder) if folder_wchain == 'intranet_workflow' and \ review_state != 'internally_published': pw.doActionFor(folder, 'publish_internally') import transaction transaction.commit()
def demo_steps(context): """ Run steps to prepare a demo. """ if context.readDataFile('s17.person-demo.txt') is None: return portal = context.getSite() portal.invokeFactory('Folder', 'Persons') folder = portal['Persons'] list_users = [{'name': 'marcelo-santos', 'password': '******', 'number': '1', 'birthday': (1985, 2, 17)}, {'name': 'marcelo-alves', 'password': '******', 'number': '2', 'birthday': (1983, 6, 01)}, {'name': 'julia-alvarez', 'password': '******', 'number': '3', 'birthday': (1988, 10, 26)}, {'name': 'juan-perez', 'password': '******', 'number': '4', 'birthday': (1981, 1, 15)}, {'name': 'gustavo-roner', 'password': '******', 'number': '5', 'birthday': (1986, 2, 15)}] for user in list_users: create_user(user['name'], user['password'], portal) # Set behaviors to person behaviors = ['s17.person.behaviors.user.IPloneUser', 's17.person.behaviors.contact.IContactInfo'] fti = queryUtility(IDexterityFTI, name='Person') fti.behaviors = tuple(behaviors) for user in list_users: person = user['name'] fullname = person.split('-') birthday = user['birthday'] image = os.path.join( os.path.dirname(__file__), 'profiles', 'demo', 'images', 'picture%s.png' % user['number']) data = getFile(image).read() folder.invokeFactory( 'Person', person, birthday=datetime.date(datetime(birthday[0], birthday[1], birthday[2])), picture=NamedImage(data), given_name=fullname[0].capitalize(), surname=fullname[1].capitalize(), gender=u'm', ) if (person == 'julia-alvarez'): folder[person].gender = 'f' p1_contact = IContactInfo(folder[person]) p1_contact.emails = [ {'category': u'work', 'data': u'*****@*****.**' % person.replace('-', '.')}, {'category': u'home', 'data': u'*****@*****.**' % person.replace('-', '.')}, ] p1_contact.instant_messengers = [ {'category': u'skype', 'data': u'%s' % person.replace('-', '_')}, ] p1_contact.telephones = [ {'category': 'home', 'data': '+5511555.1213'}, {'category': 'work', 'data': '+5511316.9876'}, ] p1_ploneuser = IPloneUser(folder[person]) p1_ploneuser.user_name = person folder[person].reindexObject() review_state = folder[person].portal_workflow.getInfoFor(folder[person], 'review_state') if not review_state == 'published': folder[person].portal_workflow.doActionFor(folder[person], 'publish') review_state = folder.portal_workflow.getInfoFor(folder, 'review_state') if not review_state == 'published': folder.portal_workflow.doActionFor(folder, 'publish') import transaction transaction.commit()