1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.AddressTypes import AddressType, AddressTypes
5 from PLC.Auth import PasswordAuth
7 class UpdateAddressType(Method):
9 Updates the parameters of an existing address type with the values
10 in address_type_fields.
12 Returns 1 if successful, faults otherwise.
17 can_update = lambda (field, value): field in ['name', 'description']
18 update_fields = dict(filter(can_update, AddressType.fields.items()))
22 Mixed(AddressType.fields['address_type_id'],
23 AddressType.fields['name']),
27 returns = Parameter(int, '1 if successful')
29 def call(self, auth, address_type_id_or_name, address_type_fields):
30 if filter(lambda field: field not in self.update_fields, address_type_fields):
31 raise PLCInvalidArgument, "Invalid field specified"
33 address_types = AddressTypes(self.api, [address_type_id_or_name]).values()
35 raise PLCInvalidArgument, "No such address type"
36 address_type = address_types[0]
38 address_type.update(address_type_fields)