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