def updatePacket(self, projectID, ownerID, projectName, projectDescr, isPrivate, projectReaderIDs, projectWriterIDs): db = self.db cursor = self.cursor commHandler = CommentHandler(db, cursor) # simple: name and owner cursor.execute("UPDATE Packets_tbl SET ownerID=" + `ownerID` + " WHERE packetID=" + `projectID`) cursor.execute("UPDATE Packets_tbl SET packetName=" + `projectName` + " WHERE packetID=" + `projectID`) # private or public # again, convert Boolean values to text; otherwise they're not stored if isPrivate == False: isPrivate = 'FALSE' else: isPrivate = 'TRUE' cursor.execute("UPDATE Packets_tbl SET is_private=" + `isPrivate` + " WHERE packetID=" + `projectID`) # description packetCommLinkID = commHandler.findCommentLinkID('Packet') packetDescr = commHandler.findCommentID(projectDescr, packetCommLinkID) cursor.execute("UPDATE Packets_tbl SET packetDescription=" + `packetDescr` + " WHERE packetID=" + `projectID`) # members self.updateProjectMembers(projectID, projectReaderIDs, 'Reader') self.updateProjectMembers(projectID, projectWriterIDs, 'Writer')
def insertPacket(self, packet): db = self.db cursor = self.cursor # extract all attributes from 'packet' projectID = packet.getNumber() # Owner is a User instance. Get his user ID owner = packet.getOwner() packetOwner = owner.getUserID() packetName = packet.getName() packetDescription = packet.getDescription() # may be empty packetReaders = packet.getReaders() # list of User instances packetWriters = packet.getWriters() # Create a Comment table entry for Project description commHandler = CommentHandler(db, cursor) # select 'Packet' commentLinkID packetCommLinkID = commHandler.findCommentLinkID('Packet') descrCommID = commHandler.insertComment(packetCommLinkID, packetDescription) # Private or public #isPrivate = packet.isPrivate() # convert Boolean values to text, not stored otherwise if packet.isPrivate() == False: isPrivate = 'FALSE' else: isPrivate = 'TRUE' cursor.execute("INSERT INTO Packets_tbl(packetID, ownerID, packetName, packetDescription, is_private) VALUES(" + `projectID` + ", " + `packetOwner` + ", " + `packetName` + ", " + `descrCommID` + ", " + `isPrivate` + ")") packetID = int(db.insert_id()) self.insertPacketReaders(packetID, packetReaders) self.insertPacketWriters(packetID, packetWriters) return packetID