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

PLC/Methods/UpdateAttribute.py

index cffc9da..2ecfe45 100644 (file)
@@ -4,18 +4,19 @@ from PLC.Parameter import Parameter, Mixed
 from PLC.Attributes import Attribute, Attributes
 from PLC.Auth import PasswordAuth
 
+can_update = lambda (field, value): field in \
+             ['description', 'min_role_id']
+
 class UpdateAttribute(Method):
     """
     Updates the parameters of an existing attribute with the values in
-    update_fields.
+    attribute_fields.
 
     Returns 1 if successful, faults otherwise.
     """
 
     roles = ['admin']
 
-    can_update = lambda (field, value): field in \
-                 ['description', 'min_role_id']
     update_fields = dict(filter(can_update, Attribute.fields.items()))
 
     accepts = [
@@ -27,16 +28,15 @@ class UpdateAttribute(Method):
 
     returns = Parameter(int, '1 if successful')
 
-    def call(self, auth, attribute_id_or_name, update_fields):
-        if filter(lambda field: field not in self.update_fields, update_fields):
-            raise PLCInvalidArgument, "Invalid field specified"
+    def call(self, auth, attribute_id_or_name, attribute_fields):
+        attribute_fields = dict(filter(can_update, attribute_fields.items()))
 
         attributes = Attributes(self.api, [attribute_id_or_name]).values()
         if not attributes:
             raise PLCInvalidArgument, "No such attribute"
         attribute = attributes[0]
 
-        attribute.update(update_fields)
+        attribute.update(attribute_fields)
 
         attribute.sync()