svn keywords
[plcapi.git] / PLC / Methods / AddAddressType.py
1 # $Id$
2 # $URL$
3 from PLC.Faults import *
4 from PLC.Method import Method
5 from PLC.Parameter import Parameter, Mixed
6 from PLC.AddressTypes import AddressType, AddressTypes
7 from PLC.Auth import Auth
8
9 can_update = lambda (field, value): field not in ['address_type_id']
10
11 class AddAddressType(Method):
12     """
13     Adds a new address type. Fields specified in address_type_fields
14     are used.
15
16     Returns the new address_type_id (> 0) if successful, faults otherwise.
17     """
18
19     roles = ['admin']
20
21     address_type_fields = dict(filter(can_update, AddressType.fields.items()))
22
23     accepts = [
24         Auth(),
25         address_type_fields
26         ]
27
28     returns = Parameter(int, 'New address_type_id (> 0) if successful')
29         
30
31     def call(self, auth, address_type_fields):
32         address_type_fields = dict(filter(can_update, address_type_fields.items()))
33         address_type = AddressType(self.api, address_type_fields)
34         address_type.sync()
35
36         self.event_objects = {'AddressType' : [address_type['address_type_id']]}
37         
38         return address_type['address_type_id']