| 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 | |
|---|
| 11 | class CodeReviewStruct(object): |
|---|
| 12 | "Stores a Code Review Entry" |
|---|
| 13 | |
|---|
| 14 | #Individual CodeReview ID Number |
|---|
| 15 | IDReview = "" |
|---|
| 16 | |
|---|
| 17 | #Author's username |
|---|
| 18 | Author = "" |
|---|
| 19 | |
|---|
| 20 | #Status of a code review |
|---|
| 21 | Status = "" |
|---|
| 22 | |
|---|
| 23 | #Date created (using Trac's internal representation) |
|---|
| 24 | DateCreate = 0 |
|---|
| 25 | |
|---|
| 26 | date_closed = 0 |
|---|
| 27 | |
|---|
| 28 | #Name of the CodeReview |
|---|
| 29 | Name = "" |
|---|
| 30 | |
|---|
| 31 | #Author's notes |
|---|
| 32 | Notes = "" |
|---|
| 33 | |
|---|
| 34 | def __init__(self, row): |
|---|
| 35 | if row is not None: |
|---|
| 36 | #initialize variables |
|---|
| 37 | self.IDReview = row[0] |
|---|
| 38 | self.Author = row[1] |
|---|
| 39 | self.Status = row[2] |
|---|
| 40 | self.DateCreate = row[3] |
|---|
| 41 | self.Name = row[4] |
|---|
| 42 | self.Notes = row[5] |
|---|
| 43 | self.date_closed = row[6] |
|---|
| 44 | |
|---|
| 45 | def save(self, db): |
|---|
| 46 | if self.IDReview == "": |
|---|
| 47 | #Add information to a new database entry |
|---|
| 48 | cursor = db.cursor() |
|---|
| 49 | cursor.execute(""" |
|---|
| 50 | INSERT INTO peer_review (owner, status, created, name, notes) |
|---|
| 51 | VALUES (%s, %s, %s, %s, %s) |
|---|
| 52 | """, (self.Author, self.Status, self.DateCreate, |
|---|
| 53 | self.Name, self.Notes)) |
|---|
| 54 | self.IDReview = db.get_last_id(cursor, 'peer_review', 'review_id') |
|---|
| 55 | db.commit() |
|---|
| 56 | else: |
|---|
| 57 | #Update information in existing database entry |
|---|
| 58 | cursor = db.cursor() |
|---|
| 59 | cursor.execute(""" |
|---|
| 60 | UPDATE peer_review SET owner=%s, status=%s, created=%s, |
|---|
| 61 | name=%s, notes=%s WHERE review_id=%s |
|---|
| 62 | """, (self.Author, self.Status, self.DateCreate, self.Name, |
|---|
| 63 | self.Notes, self.IDReview)) |
|---|
| 64 | db.commit() |
|---|
| 65 | return self.IDReview |
|---|