3 from PLC.Faults import *
4 from PLC.Method import Method
5 from PLC.Parameter import Parameter, Mixed
6 from PLC.Persons import Person, Persons
7 from PLC.Auth import Auth
9 can_update = lambda (field, value): field in \
10 ['first_name', 'last_name', 'title',
11 'email', 'password', 'phone', 'url', 'bio']
13 class AddPerson(Method):
15 Adds a new account. Any fields specified in person_fields are
16 used, otherwise defaults are used.
18 Accounts are disabled by default. To enable an account, use
21 Returns the new person_id (> 0) if successful, faults otherwise.
24 roles = ['admin', 'pi']
26 person_fields = dict(filter(can_update, Person.fields.items()))
33 returns = Parameter(int, 'New person_id (> 0) if successful')
35 def call(self, auth, person_fields):
36 person_fields = dict(filter(can_update, person_fields.items()))
37 person_fields['enabled'] = False
38 person = Person(self.api, person_fields)
42 self.event_objects = {'Person': [person['person_id']]}
43 self.message = 'Person %d added' % person['person_id']
45 return person['person_id']