Beispiel #1
1
    def comment_text(self):
        """Return a text representation of bug comments."""

        def build_message(text):
            mailwrapper = MailWrapper(width=72)
            text = mailwrapper.format(text)
            message = MIMEText(text.encode('utf-8'),
                'plain', 'utf-8')
            # This is redundant and makes the template noisy
            del message['MIME-Version']
            return message

        from lp.bugs.browser.bugtask import (
            get_visible_comments, get_comments_for_bugtask)

        # XXX: kiko 2007-10-31: for some reason, get_comments_for_bugtask
        # takes a task, not a bug. For now live with it.
        first_task = self.bugtasks[0]
        all_comments = get_comments_for_bugtask(first_task)
        comments = get_visible_comments(all_comments[1:])

        comment_mime = MIMEMultipart()
        message = build_message(self.context.description)
        comment_mime.attach(message)

        for comment in comments:
            message = build_message(comment.text_for_display)
            message['Author'] = comment.owner.unique_displayname.encode(
                'utf-8')
            message['Date'] = format_rfc2822_date(comment.datecreated)
            message['Message-Id'] = comment.rfc822msgid
            comment_mime.attach(message)

        return comment_mime.as_string().decode('utf-8')
 def setUp(self):
     TestCaseWithFactory.setUp(self)
     login('[email protected] ')
     self.bug = self.factory.makeBug()
     commenter = self.factory.makePerson()
     self.bug.newMessage(commenter, 'Comment Subject', 'Comment content')
     comments = get_comments_for_bugtask(self.bug.bugtasks[0])
     self.comment = comments[1]
     comment_view = getMultiAdapter((self.comment, LaunchpadTestRequest()),
                                    name="+box")
     self.expected_comment_html = str(comment_view())
     self.message_path = '/%s/+bug/%s/comments/1' % (
         self.bug.bugtasks[0].product.name, self.bug.id)
     self.webservice = LaunchpadWebServiceCaller('launchpad-library',
                                                 'salgado-change-anything')
 def setUp(self):
     TestCaseWithFactory.setUp(self)
     login('[email protected] ')
     self.bug = self.factory.makeBug()
     commenter = self.factory.makePerson()
     self.bug.newMessage(
         commenter, 'Comment Subject', 'Comment content')
     comments = get_comments_for_bugtask(self.bug.bugtasks[0])
     self.comment = comments[1]
     comment_view = getMultiAdapter(
         (self.comment, LaunchpadTestRequest()), name="+box")
     self.expected_comment_html = str(comment_view())
     self.message_path = '/%s/+bug/%s/comments/1' % (
         self.bug.bugtasks[0].product.name, self.bug.id)
     self.webservice = LaunchpadWebServiceCaller(
         'launchpad-library', 'salgado-change-anything')
Beispiel #4
0
    def comments(self):
        """Return the comments to be displayed for a bug watch.

        If the current user is not a member of the Launchpad developers
        team, no comments will be returned.
        """
        bug_comments = get_comments_for_bugtask(self.context.bug.bugtasks[0],
                                                truncate=True)

        # Filter out those comments that don't pertain to this bug
        # watch.
        displayed_comments = []
        for bug_comment in bug_comments:
            if bug_comment.bugwatch == self.context:
                displayed_comments.append(bug_comment)

        return displayed_comments
Beispiel #5
0
    def comments(self):
        """Return the comments to be displayed for a bug watch.

        If the current user is not a member of the Launchpad developers
        team, no comments will be returned.
        """
        bug_comments = get_comments_for_bugtask(self.context.bug.bugtasks[0],
            truncate=True)

        # Filter out those comments that don't pertain to this bug
        # watch.
        displayed_comments = []
        for bug_comment in bug_comments:
            if bug_comment.bugwatch == self.context:
                displayed_comments.append(bug_comment)

        return displayed_comments
def serialise_bugtask(bugtask):
    bug = bugtask.bug
    bug_node = ET.Element('bug', id=str(bug.id))
    bug_node.text = bug_node.tail = '\n'

    addnode(bug_node, 'private', str(bug.private))
    addnode(bug_node, 'security_related', str(bug.security_related))
    if bug.duplicateof is not None:
        addnode(bug_node, 'duplicateof', str(bug.duplicateof.id))
    addnode(bug_node, 'datecreated',
            bug.datecreated.strftime('%Y-%m-%dT%H:%M:%SZ'))
    if bug.name is not None:
        addnode(bug_node, 'nickname', bug.name)
    addnode(bug_node, 'title', bug.title)
    addnode(bug_node, 'description', bug.description)
    addperson(bug_node, 'reporter', bug.owner)

    # Information from bug task:
    addnode(bug_node, 'status', bugtask.status.name)
    addnode(bug_node, 'importance', bugtask.importance.name)
    if bugtask.milestone is not None:
        addnode(bug_node, 'milestone', bugtask.milestone.name)
    if bugtask.assignee is not None:
        addperson(bug_node, 'assignee', bugtask.assignee)

    if bug.tags:
        tags_node = ET.SubElement(bug_node, 'tags')
        tags_node.text = tags_node.tail = '\n'
        for tag in bug.tags:
            addnode(tags_node, 'tag', tag)

    subscribers = bug.getDirectSubscribers()
    if subscribers:
        subs_node = ET.SubElement(bug_node, 'subscriptions')
        subs_node.text = subs_node.tail = '\n'
        for person in subscribers:
            addperson(subs_node, 'subscriber', person)

    for comment in get_comments_for_bugtask(bugtask):
        comment_node = ET.SubElement(bug_node, 'comment')
        comment_node.text = comment_node.tail = '\n'
        addperson(comment_node, 'sender', comment.owner)
        addnode(comment_node, 'date',
                comment.datecreated.strftime('%Y-%m-%dT%H:%M:%SZ'))
        addnode(comment_node, 'text', comment.text_for_display)
        for attachment in comment.bugattachments:
            attachment_node = ET.SubElement(comment_node,
                                            'attachment',
                                            href=ProxiedLibraryFileAlias(
                                                attachment.libraryfile,
                                                attachment).http_url)
            attachment_node.text = attachment_node.tail = '\n'
            addnode(attachment_node, 'type', attachment.type.name)
            addnode(attachment_node, 'filename',
                    attachment.libraryfile.filename)
            addnode(attachment_node, 'title', attachment.title)
            addnode(attachment_node, 'mimetype',
                    attachment.libraryfile.mimetype)
            # Attach the attachment file contents, base 64 encoded.
            addnode(attachment_node, 'contents',
                    base64.encodestring(attachment.libraryfile.read()))

    return bug_node
def serialise_bugtask(bugtask):
    bug = bugtask.bug
    bug_node = ET.Element('bug', id=str(bug.id))
    bug_node.text = bug_node.tail = '\n'

    addnode(bug_node, 'private', str(bug.private))
    addnode(bug_node, 'security_related', str(bug.security_related))
    if bug.duplicateof is not None:
        addnode(bug_node, 'duplicateof', str(bug.duplicateof.id))
    addnode(bug_node, 'datecreated',
            bug.datecreated.strftime('%Y-%m-%dT%H:%M:%SZ'))
    if bug.name is not None:
        addnode(bug_node, 'nickname', bug.name)
    addnode(bug_node, 'title', bug.title)
    addnode(bug_node, 'description', bug.description)
    addperson(bug_node, 'reporter', bug.owner)

    # Information from bug task:
    addnode(bug_node, 'status', bugtask.status.name)
    addnode(bug_node, 'importance', bugtask.importance.name)
    if bugtask.milestone is not None:
        addnode(bug_node, 'milestone', bugtask.milestone.name)
    if bugtask.assignee is not None:
        addperson(bug_node, 'assignee', bugtask.assignee)

    if bug.tags:
        tags_node = ET.SubElement(bug_node, 'tags')
        tags_node.text = tags_node.tail = '\n'
        for tag in bug.tags:
            addnode(tags_node, 'tag', tag)

    subscribers = bug.getDirectSubscribers()
    if subscribers:
        subs_node = ET.SubElement(bug_node, 'subscriptions')
        subs_node.text = subs_node.tail = '\n'
        for person in subscribers:
            addperson(subs_node, 'subscriber', person)

    for comment in get_comments_for_bugtask(bugtask):
        comment_node = ET.SubElement(bug_node, 'comment')
        comment_node.text = comment_node.tail = '\n'
        addperson(comment_node, 'sender', comment.owner)
        addnode(comment_node, 'date',
                comment.datecreated.strftime('%Y-%m-%dT%H:%M:%SZ'))
        addnode(comment_node, 'text', comment.text_for_display)
        for attachment in comment.bugattachments:
            attachment_node = ET.SubElement(
                comment_node, 'attachment',
                href=ProxiedLibraryFileAlias(
                    attachment.libraryfile, attachment).http_url)
            attachment_node.text = attachment_node.tail = '\n'
            addnode(attachment_node, 'type', attachment.type.name)
            addnode(attachment_node, 'filename',
                    attachment.libraryfile.filename)
            addnode(attachment_node, 'title', attachment.title)
            addnode(attachment_node, 'mimetype',
                    attachment.libraryfile.mimetype)
            # Attach the attachment file contents, base 64 encoded.
            addnode(attachment_node, 'contents',
                    base64.encodestring(attachment.libraryfile.read()))

    return bug_node