コード例 #1
0
ファイル: PloneboardConversation.py プロジェクト: a25kk/stv2
    def addComment( self, title, text, creator=None, files=None):
        """Adds a new comment with subject and body."""
        id = self.generateId(prefix='')
        if not title:
            title = self.Title()


        m = _createObjectByType('PloneboardComment', self, id)
        
        # XXX: There is some permission problem with AT write_permission
        # and using **kwargs in the _createObjectByType statement. 
        m.setTitle(title)
        m.setText(text)
        if creator is not None:
            m.setCreators([creator])
        
        # Create files in message
        if files:
            for file in files:
                # Get raw filedata, not persistent object with reference to tempstorage
                attachment = File(file.getId(), file.title_or_id(), str(file.data), file.getContentType())
                m.addAttachment(attachment)

        # If this comment is being added by anonymous, make sure that the true
        # owner in zope is the owner of the forum, not the parent comment or
        # conversation. Otherwise, that owner may be able to view or delete
        # the comment.
        membership = getToolByName(self, 'portal_membership')
        if membership.isAnonymousUser():
            forum = self.getForum()
            utils.changeOwnershipOf(m, forum.owner_info()['id'], False)

        self.reindexObject() # Sets modified
        return m
コード例 #2
0
    def addReply(self,
                 title,
                 text,
                 creator=None,
                 files=None):
        """Add a reply to this comment."""

        conv = self.getConversation()

        id = conv.generateId(prefix='')
        if not title:
            title = conv.Title()
            if not title.lower().startswith('re:'):
                title = 'Re: ' + title

        msg = _createObjectByType(self.portal_type, conv, id)

        # XXX: There is some permission problem with AT write_permission
        # and using **kwargs in the _createObjectByType statement.
        msg.setTitle(title)
        msg.setText(text)
        msg.setInReplyTo(self.UID())

        if creator is not None:
            msg.setCreators([creator])

        # Create files in message
        if files:
            for attachment in files:
                # Get raw filedata, not persistent object with reference to
                # tempstorage file.data might in fact be OFS.Image.Pdata - str
                # will piece it all together
                msg_attachment = File(
                    attachment.getId(),
                    attachment.title_or_id(),
                    str(attachment.data),
                    attachment.getContentType()
                )
                msg.addAttachment(msg_attachment)

        # If this comment is being added by anonymous, make sure that the true
        # owner in zope is the owner of the forum, not the parent comment or
        # conversation. Otherwise, that owner may be able to view or delete
        # the comment.
        membership = getToolByName(self, 'portal_membership')
        if membership.isAnonymousUser():
            forum = self.getConversation().getForum()
            utils.changeOwnershipOf(msg, forum.owner_info()['id'], False)

        event.notify(ObjectInitializedEvent(msg))
        msg.unmarkCreationFlag()
        msg.reindexObject()
        conv.reindexObject()  # Sets modified
        return msg
コード例 #3
0
    def addReply(self,
                 title,
                 text,
                 creator=None,
                 files=None):
        """Add a reply to this comment."""

        conv = self.getConversation()

        id = conv.generateId(prefix='')
        if not title:
            title = conv.Title()
            if not title.lower().startswith('re:'):
                title = 'Re: ' + title

        msg = _createObjectByType(self.portal_type, conv, id)

        # XXX: There is some permission problem with AT write_permission
        # and using **kwargs in the _createObjectByType statement.
        msg.setTitle(title)
        msg.setText(text)
        msg.setInReplyTo(self.UID())

        if creator is not None:
            msg.setCreators([creator])

        # Create files in message
        if files:
            for attachment in files:
                # Get raw filedata, not persistent object with reference to
                # tempstorage file.data might in fact be OFS.Image.Pdata - str
                # will piece it all together
                msg_attachment = File(
                    attachment.getId(),
                    attachment.title_or_id(),
                    str(attachment.data),
                    attachment.getContentType()
                )
                msg.addAttachment(msg_attachment)

        # If this comment is being added by anonymous, make sure that the true
        # owner in zope is the owner of the forum, not the parent comment or
        # conversation. Otherwise, that owner may be able to view or delete
        # the comment.
        membership = getToolByName(self, 'portal_membership')
        if membership.isAnonymousUser():
            forum = self.getConversation().getForum()
            utils.changeOwnershipOf(msg, forum.owner_info()['id'], False)

        event.notify(ObjectInitializedEvent(msg))
        msg.unmarkCreationFlag()
        msg.reindexObject()
        conv.reindexObject()  # Sets modified
        return msg
コード例 #4
0
    def addComment( self, title, text, creator=None, files=None):
        """Adds a new comment with subject and body."""
        id = self.generateId(prefix='')
        if not title:
            title = self.Title()


        m = _createObjectByType('PloneboardComment', self, id)

        # XXX: There is some permission problem with AT write_permission
        # and using **kwargs in the _createObjectByType statement.
        m.setTitle(title)
        m.setText(text)
        if creator is not None:
            m.setCreators([creator])

        # Create files in message
        if files:
            for file in files:
                # Get raw filedata, not persistent object with reference to tempstorage
                attachment = File(file.getId(), file.title_or_id(), str(file.data), file.getContentType())
                m.addAttachment(attachment)

        # If this comment is being added by anonymous, make sure that the true
        # owner in zope is the owner of the forum, not the parent comment or
        # conversation. Otherwise, that owner may be able to view or delete
        # the comment.
        membership = getToolByName(self, 'portal_membership')
        if membership.isAnonymousUser():
            forum = self.getForum()
            utils.changeOwnershipOf(m, forum.owner_info()['id'], False)

        event.notify(ObjectInitializedEvent(m))
        m.indexObject()

        self.reindexObject() # Sets modified
        return m