1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.Attributes import Attribute, Attributes
5 from PLC.Auth import PasswordAuth
7 class UpdateAttribute(Method):
9 Updates the parameters of an existing attribute with the values in
12 Returns 1 if successful, faults otherwise.
17 can_update = lambda (field, value): field in \
18 ['description', 'min_role_id']
19 update_fields = dict(filter(can_update, Attribute.fields.items()))
23 Mixed(Attribute.fields['attribute_id'],
24 Attribute.fields['name']),
28 returns = Parameter(int, '1 if successful')
30 def call(self, auth, attribute_id_or_name, update_fields):
31 if filter(lambda field: field not in self.update_fields, update_fields):
32 raise PLCInvalidArgument, "Invalid field specified"
34 attributes = Attributes(self.api, [attribute_id_or_name]).values()
36 raise PLCInvalidArgument, "No such attribute"
37 attribute = attributes[0]
39 attribute.update(update_fields)