X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=trunk%2FPLC%2FMethods%2FUpdateAddressType.py;fp=trunk%2FPLC%2FMethods%2FUpdateAddressType.py;h=922c9409bf47ebd921851d4a7ddafda710603195;hb=5a4c1b1278ffa01e630fde47f7c54888ed20a576;hp=0000000000000000000000000000000000000000;hpb=cee5ab52df1c9f38b6eaff2dd354cb22f59028c7;p=plcapi.git diff --git a/trunk/PLC/Methods/UpdateAddressType.py b/trunk/PLC/Methods/UpdateAddressType.py new file mode 100644 index 0000000..922c940 --- /dev/null +++ b/trunk/PLC/Methods/UpdateAddressType.py @@ -0,0 +1,42 @@ +from PLC.Faults import * +from PLC.Method import Method +from PLC.Parameter import Parameter, Mixed +from PLC.AddressTypes import AddressType, AddressTypes +from PLC.Auth import Auth + +can_update = lambda (field, value): field in ['name', 'description'] + +class UpdateAddressType(Method): + """ + Updates the parameters of an existing address type with the values + in address_type_fields. + + Returns 1 if successful, faults otherwise. + """ + + roles = ['admin'] + + address_type_fields = dict(filter(can_update, AddressType.fields.items())) + + accepts = [ + Auth(), + Mixed(AddressType.fields['address_type_id'], + AddressType.fields['name']), + address_type_fields + ] + + returns = Parameter(int, '1 if successful') + + def call(self, auth, address_type_id_or_name, address_type_fields): + address_type_fields = dict(filter(can_update, address_type_fields.items())) + + address_types = AddressTypes(self.api, [address_type_id_or_name]) + if not address_types: + raise PLCInvalidArgument, "No such address type" + address_type = address_types[0] + + address_type.update(address_type_fields) + address_type.sync() + self.event_objects = {'AddressType': [address_type['address_type_id']]} + + return 1