get rid of svn keywords once and for good
[plcapi.git] / PLC / Methods / AddTagType.py
1 #
2 # Thierry Parmentelat - INRIA
3 #
4
5 from PLC.Faults import *
6 from PLC.Method import Method
7 from PLC.Parameter import Parameter, Mixed
8 from PLC.TagTypes import TagType, TagTypes
9 from PLC.Auth import Auth
10
11 can_update = lambda (field, value): field in \
12              ['tagname', 'description', 'category']
13
14 class AddTagType(Method):
15     """
16     Adds a new type of node tag.
17     Any fields specified are used, otherwise defaults are used.
18
19     Returns the new node_tag_id (> 0) if successful,
20     faults otherwise.
21     """
22
23     roles = ['admin']
24
25     tag_type_fields = dict(filter(can_update, TagType.fields.items()))
26
27     accepts = [
28         Auth(),
29         tag_type_fields
30         ]
31
32     returns = Parameter(int, 'New node_tag_id (> 0) if successful')
33
34
35     def call(self, auth, tag_type_fields):
36         tag_type_fields = dict(filter(can_update, tag_type_fields.items()))
37         tag_type = TagType(self.api, tag_type_fields)
38         tag_type.sync()
39
40         self.object_ids = [tag_type['tag_type_id']]
41
42         return tag_type['tag_type_id']