get rid of svn keywords once and for good
[plcapi.git] / PLC / Methods / AddAddressType.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 not in ['address_type_id']
8
9 class AddAddressType(Method):
10     """
11     Adds a new address type. Fields specified in address_type_fields
12     are used.
13
14     Returns the new address_type_id (> 0) 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         address_type_fields
24         ]
25
26     returns = Parameter(int, 'New address_type_id (> 0) if successful')
27
28
29     def call(self, auth, address_type_fields):
30         address_type_fields = dict(filter(can_update, address_type_fields.items()))
31         address_type = AddressType(self.api, address_type_fields)
32         address_type.sync()
33
34         self.event_objects = {'AddressType' : [address_type['address_type_id']]}
35
36         return address_type['address_type_id']