/[glsr]/trunk/site/comment.py
Gentoo

Contents of /trunk/site/comment.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 137 - (show annotations) (download) (as text)
Mon Sep 19 00:34:46 2005 UTC (8 years, 10 months ago) by hadfield
File MIME type: text/x-python
File size: 1970 byte(s)
implemented script viewing and script commenting. some minor bug fixes
1 # Copyright 2005 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 #
4
5 """The DB access module for the comment table.
6
7 Implements all functions necessary for creating, modifying, and managing
8 comments.
9 """
10
11 __revision__ = "$Id$"
12 __author__ = "Scott Hadfield <hadfield@gentoo.org>"
13 __modulename__ = "comment"
14
15 from glsr.setup import config
16 from glsr.core.db.mysql import SQLdb
17
18 def create_comment(submitter_id, script_id, subscript_id, subject, body):
19 """Add a new comment to the database."""
20
21 sql_handle = SQLdb(config.db)
22
23 # Add the comment to the database
24 sql_handle.query(
25 "INSERT INTO %(prefix)scomment " % {'prefix': config.db['prefix']} +
26 "(comment_submitter_id, comment_script_id, comment_subscript_id," +
27 " comment_date, comment_subject, comment_body)" +
28 " VALUES (%s, %s, %s, NOW(), %s, %s)",
29 (submitter_id, script_id, subscript_id, subject, body), fetch = "none")
30
31 # Get the newly inserted comments id
32 results = sql_handle.query("SELECT LAST_INSERT_ID() as id", fetch = "one")
33 assert(results.has_key("id"))
34
35 return results["id"]
36
37 def list_comments(columns = None, constraint = None):
38 """Return selected columns from all rows in the comment table.
39
40 This is basically a copy of the list_all function in user.py
41 """
42
43 if columns is None:
44 return []
45 else:
46 columns = ", ".join(columns)
47
48 where_clause = ""
49 if constraint is not None:
50 where_clause = " AND ".join(["%s = %%s" % key
51 for key in constraint])
52 if where_clause != "":
53 where_clause = "WHERE " + where_clause
54 else:
55 constraint = {}
56
57 results = SQLdb(config.db).query(
58 "SELECT %(columns)s FROM %(prefix)scomment %(where)s" %
59 {'columns': columns, 'prefix': config.db['prefix'],
60 'where': where_clause}, constraint.values(), fetch="all")
61
62 return results

Properties

Name Value
svn:keywords Id

  ViewVC Help
Powered by ViewVC 1.1.20