1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.Addresses import Address, Addresses
5 from PLC.Auth import PasswordAuth
7 can_update = lambda (field, value): field in \
8 ['line1', 'line2', 'line3',
9 'city', 'state', 'postalcode', 'country']
11 class UpdateAddress(Method):
13 Updates the parameters of an existing address with the values in
16 PIs may only update addresses of their own sites.
18 Returns 1 if successful, faults otherwise.
21 roles = ['admin', 'pi']
23 address_fields = dict(filter(can_update, Address.fields.items()))
24 for field in address_fields.values():
29 Address.fields['address_id'],
33 returns = Parameter(int, '1 if successful')
35 def call(self, auth, address_id, address_fields):
36 address_fields = dict(filter(can_update, address_fields.items()))
38 # Get associated address details
39 addresses = Addresses(self.api, [address_id]).values()
41 raise PLCInvalidArgument, "No such address"
42 address = addresses[0]
44 if 'admin' not in self.caller['roles']:
45 if address['site_id'] not in self.caller['site_ids']:
46 raise PLCPermissionDenied, "Address must be associated with one of your sites"
48 address.update(address_fields)