From: Mark Huang Date: Fri, 3 Nov 2006 16:11:42 +0000 (+0000) Subject: add messages interface X-Git-Tag: pycurl-7_13_1~386 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=e6f1cfc3e60c97f756858da04067e060d5d491d1;p=plcapi.git add messages interface --- diff --git a/PLC/Messages.py b/PLC/Messages.py new file mode 100644 index 00000000..11b7433f --- /dev/null +++ b/PLC/Messages.py @@ -0,0 +1,42 @@ +# +# Functions for interacting with the messages table in the database +# +# Tony Mack +# Copyright (C) 2006 The Trustees of Princeton University +# +# $Id: Messages.py,v 1.4 2006/10/31 21:46:14 mlhuang Exp $ +# + +from PLC.Parameter import Parameter +from PLC.Table import Row, Table + +class Message(Row): + """ + Representation of a row in the messages table. + """ + + table_name = 'messages' + primary_key = 'message_id' + fields = { + 'message_id': Parameter(str, "Message identifier"), + 'template': Parameter(str, "Message template", nullok = True), + 'enabled': Parameter(bool, "Message is enabled"), + } + +class Messages(Table): + """ + Representation of row(s) from the messages table in the database. + """ + + def __init__(self, api, message_ids, enabled = None): + self.api = api + + sql = "SELECT %s from messages" % ", ".join(Message.fields) + + if enabled is not None: + sql += " WHERE enabled IS %(enabled)s" + + rows = self.api.db.selectall(sql, locals()) + + for row in rows: + self[row['message_id']] = Message(api, row)