from user import MaloneUser from attachment import MaloneAttachment from utils import escapeInvalidChars class MaloneIssueComment(object): """ A comment to be exported to XML for Malone """ def __init__(self): self._attachments = [] def getSubject(self): return self._subject def setSubject(self, subject): self._subject = subject subject = property(getSubject, setSubject) def getCommentBody(self): return self._commentBody def setCommentBody(self, body): self._commentBody = body commentBody = property(getCommentBody, setCommentBody) def getAttachments(self): return self._attachments attachments = property(getAttachments) def addAttachment(self, attachment): self._attachments.append(attachment) def getDate(self): return self._date def setDate(self, date): self._date = date date = property(getDate, setDate) def getSender(self): return self._sender def setSender(self, sender): if not isinstance(sender, MaloneUser): raise TypeError("Initial Reporter must be a MaloneUser") self._sender = sender sender = property(getSender, setSender) def importRoundupComment(self, db, roundupCommentId): self.date = db.msg.get(roundupCommentId, 'creation') self.subject = db.msg.get(roundupCommentId, 'summary') roundupUserId = db.msg.get(roundupCommentId, 'creator') maloneSender = MaloneUser() maloneSender.importRoundupUser(db, roundupUserId) self.sender = maloneSender self.commentBody = db.msg.get(roundupCommentId, 'content') listOfFiles = db.msg.get(roundupCommentId, 'files') if listOfFiles: for fileId in listOfFiles: if db.file.hasnode(fileId): newAttachment = MaloneAttachment() newAttachment.importRoundupFile(db, fileId, self.subject) self.addAttachment(newAttachment) def toXML(self, doc, xmlBug): # COMMENT commentEl = doc.createElement("comment") xmlBug.appendChild(commentEl) # SENDER senderEl = doc.createElement("sender") username = self.sender.username.lower() username = username.replace("_","") senderEl.setAttribute('name', username) senderEl.setAttribute('email', self.sender.email) commentEl.appendChild(senderEl) senderName = doc.createTextNode(self.sender.name) senderEl.appendChild(senderName) # DATE formatedDate = "%s-%02i-%02iT%02i:%02i:%02iZ" % (self.date.year, self.date.month, self.date.day, self.date.hour, self.date.minute, self.date.second) dateEl = doc.createElement("date") commentEl.appendChild(dateEl) date = doc.createTextNode(formatedDate) dateEl.appendChild(date) # TEXT textEl = doc.createElement("text") commentEl.appendChild(textEl) # escapte bad char in db comment = escapeInvalidChars(self.commentBody) comment = doc.createTextNode(comment) textEl.appendChild(comment) # ATTACHMENT for attachment in self.attachments: attachment.toXML(doc, commentEl) # attachmentEl = doc.createElement("attachment") # attachmentEl.setAttribute("href", attachment.location) # commentEl.appendChild(attachmentEl)