- silently remove fields that can't be updated from person_fields, for
authorMark Huang <mlhuang@cs.princeton.edu>
Fri, 13 Oct 2006 20:01:06 +0000 (20:01 +0000)
committerMark Huang <mlhuang@cs.princeton.edu>
Fri, 13 Oct 2006 20:01:06 +0000 (20:01 +0000)
  backward compatibility with AdmAddPerson

PLC/Methods/AddPerson.py

index fb4b887..d80826b 100644 (file)
@@ -4,9 +4,12 @@ from PLC.Parameter import Parameter, Mixed
 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
@@ -17,8 +20,6 @@ class AddPerson(Method):
 
     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 = [
@@ -30,11 +31,9 @@ class AddPerson(Method):
 
     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