当前位置: 首页>>代码示例>>Python>>正文


Python interfaces.IComment类代码示例

本文整理汇总了Python中plone.app.discussion.interfaces.IComment的典型用法代码示例。如果您正苦于以下问题:Python IComment类的具体用法?Python IComment怎么用?Python IComment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了IComment类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_dict_operations

    def test_dict_operations(self):
        # test dict operations and acquisition wrapping

        # Create a conversation. In this case we doesn't assign it to an
        # object, as we just want to check the Conversation object API.
        conversation = IConversation(self.portal.doc1)

        # Add a comment. Note: in real life, we always create comments via the
        # factory to allow different factories to be swapped in

        comment1 = createObject('plone.Comment')
        comment1.text = 'Comment text'

        new_id1 = conversation.addComment(comment1)

        comment2 = createObject('plone.Comment')
        comment2.text = 'Comment text'

        new_id2 = conversation.addComment(comment2)

        # check if get returns a comment object, and None if the key
        # can not be found
        self.assertTrue(IComment.providedBy(conversation.get(new_id1)))
        self.assertTrue(IComment.providedBy(conversation.get(new_id2)))
        self.assertEqual(conversation.get(123), None)

        # check if keys return the ids of all comments
        self.assertEqual(len(conversation.keys()), 2)
        self.assertTrue(new_id1 in conversation.keys())
        self.assertTrue(new_id2 in conversation.keys())
        self.assertFalse(123 in conversation.keys())

        # check if items returns (key, comment object) pairs
        self.assertEqual(len(conversation.items()), 2)
        self.assertTrue((new_id1, comment1) in conversation.items())
        self.assertTrue((new_id2, comment2) in conversation.items())

        # check if values returns the two comment objects
        self.assertEqual(len(conversation.values()), 2)
        self.assertTrue(comment1 in conversation.values())
        self.assertTrue(comment2 in conversation.values())

        # check if comment ids are in iterkeys
        self.assertTrue(new_id1 in conversation.iterkeys())
        self.assertTrue(new_id2 in conversation.iterkeys())
        self.assertFalse(123 in conversation.iterkeys())

        # check if comment objects are in itervalues
        self.assertTrue(comment1 in conversation.itervalues())
        self.assertTrue(comment2 in conversation.itervalues())

        # check if iteritems returns (key, comment object) pairs
        self.assertTrue((new_id1, comment1) in conversation.iteritems())
        self.assertTrue((new_id2, comment2) in conversation.iteritems())
开发者ID:giacomos,项目名称:plone.app.discussion,代码行数:54,代码来源:test_conversation.py

示例2: test_add_comment

    def test_add_comment(self):
        # Create a conversation. In this case we doesn't assign it to an
        # object, as we just want to check the Conversation object API.
        conversation = IConversation(self.portal.doc1)

        # Add a comment. Note: in real life, we always create comments via the
        # factory to allow different factories to be swapped in

        comment = createObject('plone.Comment')
        comment.text = 'Comment text'

        new_id = conversation.addComment(comment)

        # Check that the conversation methods return the correct data
        self.assertTrue(isinstance(comment.comment_id, long))
        self.assertTrue(IComment.providedBy(conversation[new_id]))
        self.assertEqual(
            aq_base(conversation[new_id].__parent__),
            aq_base(conversation)
        )
        self.assertEqual(new_id, comment.comment_id)
        self.assertEqual(len(list(conversation.getComments())), 1)
        self.assertEqual(len(tuple(conversation.getThreads())), 1)
        self.assertEqual(conversation.total_comments(), 1)
        self.assertTrue(
            conversation.last_comment_date - datetime.utcnow() <
            timedelta(seconds=1)
        )
开发者ID:plonejp,项目名称:plone.app.discussion,代码行数:28,代码来源:test_conversation.py

示例3: getSetter

    def getSetter(self, obj, indexName):
        """Gets the setter function for the field based on the index name.

        Returns None if it can't get the function
        """
        fieldName = self.fieldNameForIndex(indexName)
        field = None
        if IComment.providedBy(obj):
            #Discussion
            field = getattr(obj, 'getField', None)
        else:
            #Archetype
            field = getattr(aq_base(obj), 'getField', None)
        # Archetypes:
        if field:
            fieldObj = field(fieldName) or field(fieldName.lower())
            if not fieldObj and fieldName.startswith('get'):
                fieldName = fieldName.lstrip('get_')
                fieldName = fieldName[0].lower() + fieldName[1:]
                fieldObj = obj.getField(fieldName)
            if fieldObj is not None:
                return fieldObj.getMutator(obj)
            return None
        # DefaultDublinCoreImpl:
        setterName = 'set' + indexName
        if getattr(aq_base(obj), setterName, None) is not None:
            return getattr(obj, setterName)
        # Dexterity
        if IDexterityContent.providedBy(obj):
            if fieldName.startswith('get'):
                fieldName = fieldName.lstrip('get_')
                fieldName = fieldName[0].lower() + fieldName[1:]
            return lambda value: setattr(obj, fieldName, value)

        return None
开发者ID:andreesg,项目名称:Products.PloneKeywordManager,代码行数:35,代码来源:tool.py

示例4: test_migrate_comment_with_creator

    def test_migrate_comment_with_creator(self):
        # Create a comment
        talkback = self.discussion.getDiscussionFor(self.doc)
        self.doc.talkback.createReply('My Title', 'My Text', Creator='Jim')
        reply = talkback.getReplies()[0]
        reply.setReplyTo(self.doc)
        reply.creation_date = DateTime(2003, 3, 11, 9, 28, 6, 'GMT')
        reply.modification_date = DateTime(2009, 7, 12, 19, 38, 7, 'GMT')
        reply.author_username = 'Jim'
        reply.email = '[email protected]'

        self._publish(reply)
        self.assertEqual(reply.Title(), 'My Title')
        self.assertEqual(reply.EditableBody(), 'My Text')
        self.assertTrue('Jim' in reply.listCreators())
        self.assertEqual(talkback.replyCount(self.doc), 1)
        self.assertEqual(reply.inReplyTo(), self.doc)
        self.assertEqual(reply.author_username, 'Jim')
        self.assertEqual(reply.email, '[email protected]')

        # Call migration script
        self.view()

        # Make sure a conversation has been created
        self.assertTrue(
            'plone.app.discussion:conversation' in IAnnotations(self.doc)
        )
        conversation = IConversation(self.doc)

        # Check migration
        self.assertEqual(conversation.total_comments, 1)
        self.assertTrue(conversation.getComments().next())
        comment1 = conversation.values()[0]
        self.assertTrue(IComment.providedBy(comment1))
        self.assertEqual(comment1.Title(), 'My Title')
        self.assertEqual(comment1.text, '<p>My Text</p>\n')
        self.assertEqual(comment1.mime_type, 'text/html')
        self.assertEqual(comment1.Creator(), 'Jim')
        self.assertEqual(
            comment1.creation_date,
            datetime(2003, 3, 11, 9, 28, 6)
        )
        self.assertEqual(
            comment1.modification_date,
            datetime(2009, 7, 12, 19, 38, 7)
        )
        self.assertEqual([
            {'comment': comment1, 'depth': 0, 'id': long(comment1.id)}
        ], list(conversation.getThreads()))
        self.assertFalse(self.doc.talkback)

        # Though this should be Jimmy, but looks like getProperty won't pick
        # up 'author_username' (reply.author_username is not None), so it's
        # propagating Creator()..?
        self.assertEqual(comment1.author_username, 'Jim')

        self.assertEqual(comment1.author_name, 'Jimmy Jones')
        self.assertEqual(comment1.author_email, '[email protected]')
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:58,代码来源:test_migration.py

示例5: moved_event

def moved_event(event):
    # only execute moved event if it's not a added or removed event since
    # those are handled elsewhere and they base off of this event class
    if (IObjectAddedEvent.providedBy(event) or
            IObjectRemovedEvent.providedBy(event)):
        return

    obj = event.object
    if not (IContentish.providedBy(obj) or IComment.providedBy(obj)):
        return
    execute_event(event)
开发者ID:ale-rt,项目名称:collective.auditlog,代码行数:11,代码来源:handlers.py

示例6: copied

def copied(event):
    """When an object is copied, execute rules assigned to its parent
    """
    obj = event.object
    if not (IContentish.providedBy(obj) or IComment.providedBy(obj)):
        return

    if is_portal_factory(obj):
        return

    execute(aq_parent(aq_inner(event.original)), event)
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:11,代码来源:handlers.py

示例7: removed

def removed(event):
    """When an IObjectRemovedEvent was received, execute rules assigned to its
     previous parent.
    """
    obj = event.object
    if not (IContentish.providedBy(obj) or IComment.providedBy(obj)):
        return

    if is_portal_factory(obj):
        return

    execute(event.oldParent, event)
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:12,代码来源:handlers.py

示例8: modified

def modified(event):
    """When an object is modified, execute rules assigned to its parent
    """

    obj = event.object
    if not (IContentish.providedBy(obj) or IComment.providedBy(obj)):
        return

    # Let the special handler take care of IObjectInitializedEvent
    for event_if in (IObjectInitializedEvent, IObjectAddedEvent,
        IObjectRemovedEvent, IContainerModifiedEvent, IObjectCopiedEvent):
        if event_if.providedBy(event):
            return

    execute_rules(event)
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:15,代码来源:handlers.py

示例9: test_migrate_comment

    def test_migrate_comment(self):

        # Create a comment
        talkback = self.discussion.getDiscussionFor(self.doc)
        self.doc.talkback.createReply('My Title', 'My Text', Creator='Jim')
        reply = talkback.getReplies()[0]
        reply.setReplyTo(self.doc)
        reply.creation_date = DateTime(2003, 3, 11, 9, 28, 6, 'GMT')
        reply.modification_date = DateTime(2009, 7, 12, 19, 38, 7, 'GMT')

        self._publish(reply)
        self.assertEqual(reply.Title(), 'My Title')
        self.assertEqual(reply.EditableBody(), 'My Text')
        self.assertTrue('Jim' in reply.listCreators())
        self.assertEqual(talkback.replyCount(self.doc), 1)
        self.assertEqual(reply.inReplyTo(), self.doc)

        # Call migration script
        self.view()

        # Make sure a conversation has been created
        self.assertTrue(
            'plone.app.discussion:conversation' in IAnnotations(self.doc)
        )
        conversation = IConversation(self.doc)

        # Check migration
        self.assertEqual(conversation.total_comments, 1)
        self.assertTrue(conversation.getComments().next())
        comment1 = conversation.values()[0]
        self.assertTrue(IComment.providedBy(comment1))
        self.assertEqual(comment1.Title(), 'My Title')
        self.assertEqual(comment1.text, '<p>My Text</p>\n')
        self.assertEqual(comment1.mime_type, 'text/html')
        self.assertEqual(comment1.Creator(), 'Jim')
        self.assertEqual(
            comment1.creation_date,
            datetime(2003, 3, 11, 9, 28, 6)
        )
        self.assertEqual(
            comment1.modification_date,
            datetime(2009, 7, 12, 19, 38, 7)
        )
        self.assertEqual([
            {'comment': comment1, 'depth': 0, 'id': long(comment1.id)}
        ], list(conversation.getThreads()))
        self.assertFalse(self.doc.talkback)
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:47,代码来源:test_migration.py

示例10: created_event

def created_event(event):
    obj = event.object

    if is_portal_factory(obj):
        return

    if IObjectCopiedEvent.providedBy(event):
        return  # ignore this event since we're listening to cloned instead
    # The object added event executes too early for Archetypes objects.
    # We need to delay execution until we receive a subsequent
    # IObjectInitializedEvent
    if IBaseObject.providedBy(obj):
        cr_handlers.init()
        cr_handlers._status.delayed_events[
            'IObjectInitializedEvent-audit-%s' % getUID(obj)] = event
    elif IContentish.providedBy(obj) or IComment.providedBy(obj):
        execute_event(event)
    else:
        return
开发者ID:ale-rt,项目名称:collective.auditlog,代码行数:19,代码来源:handlers.py

示例11: added

def added(event):
    """When an object is added, execute rules assigned to its new parent.

    There is special handling for Archetypes objects.
    """
    obj = event.object
    if is_portal_factory(obj):
        return

    # The object added event executes too early for Archetypes objects.
    # We need to delay execution until we receive a subsequent
    # IObjectInitializedEvent
    if IBaseObject.providedBy(obj):
        init()
        _status.delayed_events['IObjectInitializedEvent-%s' % _get_uid(obj)] = event
    elif IContentish.providedBy(obj) or IComment.providedBy(obj):
        execute(event.newParent, event)
    else:
        return
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:19,代码来源:handlers.py


注:本文中的plone.app.discussion.interfaces.IComment类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。