- Change .py files to use 4-space indents and no hard tab characters.
[plcapi.git] / PLC / Methods / UpdateAddress.py
index 2428b2f..4150972 100644 (file)
@@ -1,8 +1,14 @@
+# $Id$
+# $URL$
 from PLC.Faults import *
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
 from PLC.Addresses import Address, Addresses
-from PLC.Auth import PasswordAuth
+from PLC.Auth import Auth
+
+can_update = lambda (field, value): field in \
+             ['line1', 'line2', 'line3',
+              'city', 'state', 'postalcode', 'country']
 
 class UpdateAddress(Method):
     """
@@ -16,25 +22,21 @@ class UpdateAddress(Method):
 
     roles = ['admin', 'pi']
 
-    can_update = lambda (field, value): field in \
-                 ['line1', 'line2', 'line3',
-                  'city', 'state', 'postalcode', 'country']
-    update_fields = dict(filter(can_update, Address.fields.items()))
+    address_fields = dict(filter(can_update, Address.fields.items()))
 
     accepts = [
-        PasswordAuth(),
+        Auth(),
         Address.fields['address_id'],
-        update_fields
+        address_fields
         ]
 
     returns = Parameter(int, '1 if successful')
 
     def call(self, auth, address_id, address_fields):
-        if filter(lambda field: field not in self.update_fields, address_fields):
-            raise PLCInvalidArgument, "Invalid field specified"
+        address_fields = dict(filter(can_update, address_fields.items()))
 
         # Get associated address details
-        addresses = Addresses(self.api, [address_id]).values()
+        addresses = Addresses(self.api, [address_id])
         if not addresses:
             raise PLCInvalidArgument, "No such address"
         address = addresses[0]
@@ -46,4 +48,9 @@ class UpdateAddress(Method):
         address.update(address_fields)
         address.sync()
 
+        # Logging variables
+        self.event_objects = {'Address': [address['address_id']]}
+        self.message = 'Address %d updated: %s' % \
+                (address['address_id'], ", ".join(address_fields.keys()))
+
         return 1