- import Faults
[plcapi.git] / PLC / Messages.py
1 #
2 # Functions for interacting with the messages table in the database
3 #
4 # Tony Mack <tmack@cs.princeton.edu>
5 # Copyright (C) 2006 The Trustees of Princeton University
6 #
7 # $Id: Messages.py,v 1.3 2006/11/10 17:06:35 mlhuang Exp $
8 #
9
10 from PLC.Parameter import Parameter
11 from PLC.Table import Row, Table
12
13 class Message(Row):
14     """
15     Representation of a row in the messages table. 
16     """
17     
18     table_name = 'messages'
19     primary_key = 'message_id'
20     fields = {
21         'message_id': Parameter(str, "Message identifier"),
22         'subject': Parameter(str, "Message summary", nullok = True),
23         'template': Parameter(str, "Message template", nullok = True),
24         'enabled': Parameter(bool, "Message is enabled"),
25         }
26     
27 class Messages(Table):
28     """
29     Representation of row(s) from the messages table in the database. 
30     """
31
32     def __init__(self, api, message_ids, enabled = None):
33         Table.__init__(self, api, Message)
34     
35         sql = "SELECT %s from messages WHERE True" % \
36               ", ".join(Message.fields)
37
38         if message_ids:
39             sql += " AND message_id IN (%s)" %  ", ".join(map(api.db.quote, message_ids))
40
41         if enabled is not None:
42             sql += " AND enabled IS %s" % enabled
43
44         self.selectall(sql)