get rid of svn keywords once and for good
[plcapi.git] / PLC / Methods / UpdateAddressType.py
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 Auth
6
7 can_update = lambda (field, value): field in ['name', 'description']
8
9 class UpdateAddressType(Method):
10     """
11     Updates the parameters of an existing address type with the values
12     in address_type_fields.
13
14     Returns 1 if successful, faults otherwise.
15     """
16
17     roles = ['admin']
18
19     address_type_fields = dict(filter(can_update, AddressType.fields.items()))
20
21     accepts = [
22         Auth(),
23         Mixed(AddressType.fields['address_type_id'],
24               AddressType.fields['name']),
25         address_type_fields
26         ]
27
28     returns = Parameter(int, '1 if successful')
29
30     def call(self, auth, address_type_id_or_name, address_type_fields):
31         address_type_fields = dict(filter(can_update, address_type_fields.items()))
32
33         address_types = AddressTypes(self.api, [address_type_id_or_name])
34         if not address_types:
35             raise PLCInvalidArgument, "No such address type"
36         address_type = address_types[0]
37
38         address_type.update(address_type_fields)
39         address_type.sync()
40         self.event_objects = {'AddressType': [address_type['address_type_id']]}
41
42         return 1