| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | # |
|---|
| 3 | # Copyright (C) 2005-2006 Team5 |
|---|
| 4 | # All rights reserved. |
|---|
| 5 | # |
|---|
| 6 | # This software is licensed as described in the file COPYING, which |
|---|
| 7 | # you should have received as part of this distribution. |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | class ReviewCommentStruct(object): |
|---|
| 11 | """Stores a ReviewComment Entry""" |
|---|
| 12 | |
|---|
| 13 | #Individual comment ID number |
|---|
| 14 | IDComment = "-1" |
|---|
| 15 | |
|---|
| 16 | #File ID to which the comment belongs |
|---|
| 17 | IDFile = "" |
|---|
| 18 | |
|---|
| 19 | #Comment ID of the comment's hierarchically parent |
|---|
| 20 | IDParent = "-1" |
|---|
| 21 | |
|---|
| 22 | #Line number the ID refers to |
|---|
| 23 | LineNum = "" |
|---|
| 24 | |
|---|
| 25 | #Author of the comment |
|---|
| 26 | Author = "" |
|---|
| 27 | |
|---|
| 28 | #Comment's text |
|---|
| 29 | Text = "" |
|---|
| 30 | |
|---|
| 31 | #Attachment name and path |
|---|
| 32 | AttachmentPath = "" |
|---|
| 33 | |
|---|
| 34 | #Date comment created |
|---|
| 35 | DateCreate = -1 |
|---|
| 36 | |
|---|
| 37 | #Collection of comment IDs belonging to the comment's hierarchically children |
|---|
| 38 | Children = {} |
|---|
| 39 | |
|---|
| 40 | def __init__(self, row): |
|---|
| 41 | if row is not None: |
|---|
| 42 | #initialize variables |
|---|
| 43 | self.IDComment = row[0] |
|---|
| 44 | self.IDFile = row[1] |
|---|
| 45 | self.IDParent = row[2] |
|---|
| 46 | self.LineNum = row[3] |
|---|
| 47 | self.Author = row[4] |
|---|
| 48 | self.Text = row[5] |
|---|
| 49 | self.AttachmentPath = row[6] |
|---|
| 50 | self.DateCreate = row[7] |
|---|
| 51 | self.Children = {} |
|---|
| 52 | if not self.AttachmentPath: |
|---|
| 53 | self.AttachmentPath = "" |
|---|
| 54 | |
|---|
| 55 | def save(self, db): |
|---|
| 56 | if self.IDComment == "-1": |
|---|
| 57 | #Add information to a new database entry |
|---|
| 58 | cursor = db.cursor() |
|---|
| 59 | cursor.execute(""" |
|---|
| 60 | INSERT INTO peer_review_comment (file_id, parent_id, line_num, |
|---|
| 61 | author, comment, attachment_path, created) |
|---|
| 62 | VALUES (%s, %s, %s, %s, %s, %s, %s) |
|---|
| 63 | """, (self.IDFile, self.IDParent, self.LineNum, self.Author, |
|---|
| 64 | self.Text, self.AttachmentPath, self.DateCreate)) |
|---|
| 65 | self.IDComment = db.get_last_id(cursor, 'peer_review_comment', 'comment_id') |
|---|
| 66 | db.commit() |
|---|
| 67 | else: |
|---|
| 68 | #Update information in existing database entry |
|---|
| 69 | cursor = db.cursor() |
|---|
| 70 | cursor.execute(""" |
|---|
| 71 | UPDATE peer_review_comment SET file_id=%s, IDParent=%s, line_num=%s, |
|---|
| 72 | author=%s, comment=%s, attachment_path=%s, created=%s |
|---|
| 73 | WHERE comment_id=%s |
|---|
| 74 | """, (self.IDFile, self.IDParent, self.LineNum, self.Author, |
|---|
| 75 | self.Text, self.AttachmentPath, self.DateCreate, |
|---|
| 76 | self.IDComment)) |
|---|
| 77 | db.commit() |
|---|
| 78 | return self.IDComment |
|---|