10
10
11
11
12
12
class Tag (PropertySet ):
13
+ """ Define a Tag properties"""
13
14
_attrs = [
14
15
Prop ('oc:id' ),
15
16
Prop ('oc:display-name' , json = 'name' , default = 'default_tag_name' ),
@@ -22,19 +23,27 @@ class Tag(PropertySet):
22
23
class SystemTags (WebDAVApiWrapper ):
23
24
""" SystemTags API wrapper """
24
25
API_URL = '/remote.php/dav/systemtags'
25
- JSON_ABLE = True
26
26
27
27
def get_sytemtag (self , name , fields = None , json_output = None ):
28
+ """
29
+ Get attributes of a nammed tag
30
+
31
+ :param name (str): tag name
32
+ :param fields (<list>str): field names
33
+ :returns: requester response with <list>Tag in data
34
+ """
28
35
if not fields :
29
36
fields = Tag ._fields
30
- resp = self .requester .propfind (data = Tag .build_xml_propfind (
31
- fields = {'oc' : ['display-name' ] + fields }))
37
+ resp = self .requester .propfind (
38
+ data = Tag .build_xml_propfind (fields = {
39
+ 'oc' : ['display-name' ] + fields
40
+ }))
32
41
if json_output is None :
33
42
json_output = self .json_output
34
43
return Tag .from_response (resp ,
35
44
json_output = json_output ,
36
45
init_attrs = True ,
37
- filtered = ( lambda t : t .display_name == name ) )
46
+ filtered = lambda t : t .display_name == name )
38
47
39
48
def get_systemtags (self ):
40
49
"""
@@ -43,8 +52,9 @@ def get_systemtags(self):
43
52
:returns: requester response with <list>Tag in data
44
53
"""
45
54
resp = self .requester .propfind (
46
- data = Tag .build_xml_propfind (use_default = True ))
47
- return Tag .from_response (resp , json_output = (self .json_output ))
55
+ data = Tag .build_xml_propfind (use_default = True )
56
+ )
57
+ return Tag .from_response (resp , json_output = self .json_output )
48
58
49
59
def create_systemtag (self , name , ** kwargs ):
50
60
"""
@@ -53,9 +63,12 @@ def create_systemtag(self, name, **kwargs):
53
63
:param name: tag name
54
64
:returns: requester response with tag id as data
55
65
"""
56
- data = (Tag .default_get )(name = name , ** kwargs )
57
- resp = self .requester .post (data = (json .dumps (data )), headers = {
58
- 'Content-Type' : 'application/json' })
66
+ data = Tag .default_get (name = name , ** kwargs )
67
+ resp = self .requester .post (
68
+ data = json .dumps (data ),
69
+ headers = {
70
+ 'Content-Type' : 'application/json'
71
+ })
59
72
if resp .is_ok :
60
73
resp .data = int (
61
74
resp .raw .headers ['Content-Location' ].split ('/' )[(- 1 )])
@@ -64,7 +77,7 @@ def create_systemtag(self, name, **kwargs):
64
77
def delete_systemtag (self , name = None , tag_id = None ):
65
78
"""
66
79
Delete systemtag
67
-
80
+
68
81
:param name (str): tag name, not required it tag_id is provided
69
82
:tag_id (int): tag id, not required if name is provided
70
83
@@ -74,16 +87,15 @@ def delete_systemtag(self, name=None, tag_id=None):
74
87
resp = self .get_sytemtag (name , ['id' ], json_output = False )
75
88
if resp .data :
76
89
tag_id = resp .data [0 ].id
77
- elif tag_id :
78
- resp = self .requester .delete (url = (str (tag_id )))
90
+ if not tag_id : # lint only
91
+ return None
92
+ resp = self .requester .delete (url = (str (tag_id )))
79
93
return resp
80
94
81
95
82
96
class SystemTagsRelation (WebDAVApiWrapper ):
83
97
""" SystemTagsRelation API wrapper """
84
98
API_URL = '/remote.php/dav/systemtags-relations/files'
85
- JSON_ABLE = True
86
- REQUIRE_CLIENT = True
87
99
88
100
def _get_fileid_from_path (self , path ):
89
101
""" Tricky function to fetch file """
@@ -121,7 +133,8 @@ def get_systemtags_relation(self, file_id=None, **kwargs):
121
133
122
134
:returns: requester response with <list>Tag in data
123
135
"""
124
- file_id , = self ._arguments_get (['file_id' ], locals ())
136
+ file_id , = self ._arguments_get (['file_id' ], dict (file_id = file_id ,
137
+ ** kwargs ))
125
138
data = Tag .build_xml_propfind ()
126
139
resp = self .requester .propfind (additional_url = file_id , data = data )
127
140
return Tag .from_response (resp , json_output = (self .json_output ))
@@ -138,7 +151,7 @@ def delete_systemtags_relation(self, file_id=None, tag_id=None, **kwargs):
138
151
:returns: requester response
139
152
"""
140
153
file_id , tag_id = self ._arguments_get ([
141
- 'file_id' , 'tag_id' ], locals ( ))
154
+ 'file_id' , 'tag_id' ], dict ( file_id = file_id , tag_id = tag_id , ** kwargs ))
142
155
resp = self .requester .delete (url = ('{}/{}' .format (file_id , tag_id )))
143
156
return resp
144
157
@@ -163,6 +176,5 @@ def add_systemtags_relation(self, file_id=None, tag_id=None, **kwargs):
163
176
tag_id = resp .data
164
177
if not file_id :
165
178
raise ValueError ('No file found' )
166
- data = Tag .build_xml_propfind ()
167
179
resp = self .requester .put (url = ('{}/{}' .format (file_id , tag_id )))
168
180
return resp
0 commit comments