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 class AdmAddPerson(Method):
9 Adds a new account. Any fields specified in optional_vals are
10 used, otherwise defaults are used.
12 Accounts are disabled by default. To enable an account, use
13 AdmSetPersonEnabled() or AdmUpdatePerson().
15 Returns the new person_id (> 0) if successful, faults otherwise.
18 roles = ['admin', 'pi']
20 can_update = lambda (field, value): field in \
21 ['title', 'email', 'password', 'phone', 'url', 'bio']
22 update_fields = dict(filter(can_update, Person.fields.items()))
26 Person.fields['first_name'],
27 Person.fields['last_name'],
31 returns = Parameter(int, '1 if successful')
33 def call(self, auth, first_name, last_name, optional_vals = {}):
34 if filter(lambda field: field not in self.update_fields, optional_vals):
35 raise PLCInvalidArgument, "Invalid fields specified"
37 person = Person(self.api, optional_vals)
38 person['first_name'] = first_name
39 person['last_name'] = last_name
40 person['enabled'] = False
43 return person['person_id']