def getNodeText(self, jid, node): app = Zope2.app() text = '' try: portal = app.unrestrictedTraverse(self.portal_id, None) if portal is None: raise DSCException('Portal with id %s not found' % self.portal_id) setSite(portal) acl_users = getToolByName(portal, 'acl_users') user_id = unescapeNode(JID(jid).user) user = acl_users.getUserById(user_id) if user is None: raise DSCException('Invalid user %s' % user_id) newSecurityManager(None, user) ct = getToolByName(portal, 'portal_catalog') uid, html_id = node.split('#') item = ct.unrestrictedSearchResults(UID=uid) if not item: raise DSCException('Content with UID %s not found' % uid) item = ICollaborativelyEditable(item[0].getObject()) text = item.getNodeTextFromHtmlID(html_id) finally: noSecurityManager() setSite(None) return text
def test_htmlIds(self): ce = ICollaborativelyEditable(self.doc) self.assertEqual( set([ 'form-widgets-title', 'form-widgets-description', 'form-widgets-rights', 'form-widgets-textline', 'form-widgets-text', 'form.widgets.richtext' ]), set(ce.htmlIDs))
def test_nodeIds(self): uid = IUUID(self.doc) ce = ICollaborativelyEditable(self.doc) self.assertEqual( set([ uid + '#' + 'form-widgets-title', uid + '#' + 'form-widgets-description', uid + '#' + 'form-widgets-rights', uid + '#' + 'form-widgets-textline', uid + '#' + 'form-widgets-text', uid + '#' + 'form.widgets.richtext' ]), set(ce.nodeIDs))
def setNodeText(self, jid, node, text): transaction.begin() app = Zope2.app() try: try: portal = app.unrestrictedTraverse(self.portal_id, None) if portal is None: raise DSCException('Portal with id %s not found' % self.portal_id) setSite(portal) settings = getUtility(IRegistry) autosave = settings.get( 'collective.xmpp.autoSaveCollaboration', False) if not autosave: transaction.abort() return acl_users = getToolByName(portal, 'acl_users') user_id = unescapeNode(JID(jid).user) user = acl_users.getUserById(user_id) if user is None: raise DSCException('Invalid user %s' % user_id) newSecurityManager(None, user) ct = getToolByName(portal, 'portal_catalog') uid, html_id = node.split('#') item = ct.unrestrictedSearchResults(UID=uid) if not item: raise DSCException('Content with UID %s not found' % uid) item = ICollaborativelyEditable(item[0].getObject()) item.setNodeTextFromHtmlID(html_id, text) transaction.commit() except: transaction.abort() raise finally: noSecurityManager() setSite(None) app._p_jar.close() return text
def test_idToNode(self): ce = ICollaborativelyEditable(self.doc) uid = self.doc.UID() self.assertEqual(uid + '#' + 'text', ce.idToNode['text'])
def test_nodeToId(self): ce = ICollaborativelyEditable(self.doc) uid = self.doc.UID() self.assertEqual('text', ce.nodeToId[uid + '#' + 'text'])
def test_setNodeTextFromHtmlID(self): ce = ICollaborativelyEditable(self.doc) ce.setNodeTextFromHtmlID('text', 'New text') self.assertEqual('New text', self.doc.getRawText())
def test_getNodeTextFromHtmlID(self): ce = ICollaborativelyEditable(self.doc) self.assertEqual(ce.getNodeTextFromHtmlID('text'), 'Some text')
def test_nodeIds(self): uid = self.doc.UID() ce = ICollaborativelyEditable(self.doc) self.assertEqual([ uid + '#' + 'title', uid + '#' + 'description', uid + '#' + 'text' ], ce.nodeIDs)
def test_htmlIds(self): ce = ICollaborativelyEditable(self.doc) self.assertEqual(['title', 'description', 'text'], ce.htmlIDs)
def test_contentUID(self): uid = self.doc.UID() ce = ICollaborativelyEditable(self.doc) self.assertEqual(uid, ce.contentUID)
def test_idToNode(self): uid = IUUID(self.doc) ce = ICollaborativelyEditable(self.doc) self.assertEqual(uid + '#' + 'form-widgets-text', ce.idToNode['form-widgets-text'])
def test_nodeToId(self): uid = IUUID(self.doc) ce = ICollaborativelyEditable(self.doc) self.assertEqual('form-widgets-text', ce.nodeToId[uid + '#' + 'form-widgets-text'])
def test_setNodeTextFromHtmlID(self): ce = ICollaborativelyEditable(self.doc) ce.setNodeTextFromHtmlID('form-widgets-text', 'New text'.decode('utf-8')) self.assertEqual('New text', self.doc.text)