1 from PLC.Method import Method
2 from PLC.Parameter import Parameter, Mixed
3 from PLC.Filter import Filter
4 from PLC.Auth import Auth
5 from PLC.Persons import Person, Persons
6 from PLC.sendmail import sendmail
8 class NotifyPersons(Method):
10 Sends an e-mail message to the specified users. If person_filter
11 is specified and is an array of user identifiers or usernames, or
12 a struct of user attributes, only users matching the filter will
15 Returns 1 if successful.
18 roles = ['admin', 'node']
22 Mixed([Mixed(Person.fields['person_id'],
23 Person.fields['email'])],
24 Filter(Person.fields)),
25 Parameter(str, "E-mail subject"),
26 Parameter(str, "E-mail body")
29 returns = Parameter(int, '1 if successful')
31 def call(self, auth, person_filter, subject, body):
32 persons = Persons(self.api, person_filter,
33 ['person_id', 'first_name', 'last_name', 'email'])
35 raise PLCInvalidArgument, "No such user(s)"
39 To = [("%s %s" % (person['first_name'], person['last_name']),
40 person['email']) for person in persons],
45 self.event_objects = {'Person': [person['person_id'] for person in persons]}
46 self.message = subject