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