2 # Functions for interacting with the messages table in the database
4 # Tony Mack <tmack@cs.princeton.edu>
5 # Copyright (C) 2006 The Trustees of Princeton University
11 from PLC.Parameter import Parameter
12 from PLC.Table import Row, Table
13 from PLC.Filter import Filter
17 Representation of a row in the messages table.
20 table_name = 'messages'
21 primary_key = 'message_id'
23 'message_id': Parameter(str, "Message identifier"),
24 'subject': Parameter(str, "Message summary", nullok = True),
25 'template': Parameter(str, "Message template", nullok = True),
26 'enabled': Parameter(bool, "Message is enabled"),
29 class Messages(Table):
31 Representation of row(s) from the messages table in the database.
34 def __init__(self, api, message_filter = None, columns = None, enabled = None):
35 Table.__init__(self, api, Message, columns)
37 sql = "SELECT %s from messages WHERE True" % \
38 ", ".join(self.columns)
40 if enabled is not None:
41 sql += " AND enabled IS %s" % enabled
43 if message_filter is not None:
44 if isinstance(message_filter, (list, tuple, set)):
45 message_filter = Filter(Message.fields, {'message_id': message_filter})
46 sql += " AND (%s) %s" % message_filter.sql(api, "OR")
47 elif isinstance(message_filter, dict):
48 message_filter = Filter(Message.fields, message_filter)
49 sql += " AND (%s) %s" % message_filter.sql(api, "AND")