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 AddAttribute(Method):
9 Adds a new type of attribute. Any fields specified in optional_vals
10 are used, otherwise defaults are used.
12 Returns the new attribute_id (> 0) 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 Attribute.fields['name'],
27 returns = Parameter(int, 'New attribute_id (> 0) if successful')
29 def call(self, auth, name, optional_vals = {}):
30 if filter(lambda field: field not in self.update_fields, optional_vals):
31 raise PLCInvalidArgument, "Invalid field specified"
33 attribute = Attribute(self.api, optional_vals)
34 attribute['name'] = name
37 return attribute['attribute_id']