Merge from trunk
[plcapi.git] / trunk / PLC / Methods / AddMessage.py
1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter
4 from PLC.Messages import Message, Messages
5 from PLC.Auth import Auth
6
7 class AddMessage(Method):
8     """
9     Adds a new message template. Any values specified in
10     message_fields are used, otherwise defaults are used.
11
12     Returns 1 if successful, faults otherwise.
13     """
14
15     roles = ['admin']
16
17     accepts = [
18         Auth(),
19         Message.fields,
20         ]
21
22     returns = Parameter(int, '1 if successful')
23
24
25     def call(self, auth, message_fields):
26         message = Message(self.api, message_fields)
27         message.sync(insert = True)
28
29         return 1