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 object_type = 'Person'
36 def call(self, auth, person_fields):
37 person_fields = dict(filter(can_update, person_fields.items()))
38 person_fields['enabled'] = False
39 person = Person(self.api, person_fields)
43 self.object_ids = [person['person_id']]
44 self.message = 'Person %d added' % person['person_id']
46 return person['person_id']