from PLC.Persons import Person, Persons
from PLC.Auth import PasswordAuth
+can_update = lambda (field, value): field in \
+ ['title', 'email', 'password', 'phone', 'url', 'bio']
+
class AddPerson(Method):
"""
- Adds a new account. Any fields specified in optional_vals are
+ Adds a new account. Any fields specified in person_fields are
used, otherwise defaults are used.
Accounts are disabled by default. To enable an account, use
roles = ['admin', 'pi']
- can_update = lambda (field, value): field in \
- ['title', 'email', 'password', 'phone', 'url', 'bio']
update_fields = dict(filter(can_update, Person.fields.items()))
accepts = [
returns = Parameter(int, 'New person_id (> 0) if successful')
- def call(self, auth, first_name, last_name, optional_vals = {}):
- if filter(lambda field: field not in self.update_fields, optional_vals):
- raise PLCInvalidArgument, "Invalid fields specified"
-
- person = Person(self.api, optional_vals)
+ def call(self, auth, first_name, last_name, person_fields = {}):
+ person_fields = dict(filter(can_update, person_fields.items()))
+ person = Person(self.api, person_fields)
person['first_name'] = first_name
person['last_name'] = last_name
person['enabled'] = False