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 PasswordAuth
7 can_update = lambda (field, value): field in \
8 ['title', 'email', 'password', 'phone', 'url', 'bio']
10 class AddPerson(Method):
12 Adds a new account. Any fields specified in person_fields are
13 used, otherwise defaults are used.
15 Accounts are disabled by default. To enable an account, use
16 SetPersonEnabled() or UpdatePerson().
18 Returns the new person_id (> 0) if successful, faults otherwise.
21 roles = ['admin', 'pi']
23 update_fields = dict(filter(can_update, Person.fields.items()))
27 Person.fields['first_name'],
28 Person.fields['last_name'],
32 returns = Parameter(int, 'New person_id (> 0) if successful')
35 object_type = 'Person'
38 def call(self, auth, first_name, last_name, person_fields = {}):
39 person_fields = dict(filter(can_update, person_fields.items()))
40 person = Person(self.api, person_fields)
41 person['first_name'] = first_name
42 person['last_name'] = last_name
43 person['enabled'] = False
45 self.object_ids = [person['person']]
47 return person['person_id']