2 # Thierry Parmentelat - INRIA
4 from PLC.Faults import *
5 from PLC.Method import Method
6 from PLC.Parameter import Parameter, Mixed
7 from PLC.TagTypes import TagType, TagTypes
8 from PLC.Auth import Auth
10 can_update = lambda (field, value): field in \
11 ['tagname', 'description', 'category']
13 class UpdateTagType(Method):
15 Updates the parameters of an existing tag type
16 with the values in tag_type_fields.
18 Returns 1 if successful, faults otherwise.
23 tag_type_fields = dict(filter(can_update, TagType.fields.items()))
27 Mixed(TagType.fields['tag_type_id'],
28 TagType.fields['tagname']),
32 returns = Parameter(int, '1 if successful')
34 def call(self, auth, tag_type_id_or_name, tag_type_fields):
36 accepted_type_fields = dict(filter(can_update, tag_type_fields.items()))
37 rejected_keys = [ k for k in tag_type_fields if k not in accepted_type_fields ]
39 error="Cannot update TagType column(s) %r"%rejected_keys
40 if 'roles' in rejected_keys or 'role_ids' in rejected_keys:
41 error += " see AddRoleToTagType DeleteRoleFromTagType"
42 raise PLCInvalidArgument, error
44 tag_types = TagTypes(self.api, [tag_type_id_or_name])
46 raise PLCInvalidArgument, "No such tag type"
47 tag_type = tag_types[0]
49 tag_type.update(accepted_type_fields)
51 self.object_ids = [tag_type['tag_type_id']]