Skip to content

Commit ad10e52

Browse files
authored
Adding get all project comments
1 parent d4bf4a7 commit ad10e52

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

frameioclient/client.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,61 @@ def get_asset_children(self, asset_id, **kwargs):
171171
endpoint = '/assets/{}/children'.format(asset_id)
172172
return self._api_call('get', endpoint, kwargs)
173173

174+
def all_comments(client, asset_id, comment_list):
175+
176+
"""
177+
Get all comments for an asset. They come back as a
178+
list of lists. This function is used inside the get_all_project_comments function.
179+
Use that function rather than this one.
180+
"""
181+
182+
files = client.get_asset_children(asset_id)
183+
184+
for asset in files:
185+
if asset['type'] == "file":
186+
if asset['comment_count'] > 0:
187+
asset_parent_id = asset['parent_id']
188+
asset_name = asset['name']
189+
comments = client.get_comments(asset['id'])
190+
my_comment_list = [comment for comment in comments.results]
191+
for object in my_comment_list:
192+
object.update({'parent_id':asset_parent_id})
193+
object.update({'name':asset_name})
194+
comment_list.append(my_comment_list)
195+
196+
if asset['type'] == "folder":
197+
if asset['item_count'] > 0:
198+
all_comments(client, asset['id'], comment_list)
199+
200+
if asset['type'] == "version_stack":
201+
asset_name = asset['name']
202+
parent_id = asset['parent_id']
203+
vfiles = client.get_asset_children(asset['id'])
204+
205+
for asset in vfiles.results:
206+
asset_name = asset['name']
207+
parent_id = asset['parent_id']
208+
if asset['type'] == "file":
209+
if asset['comment_count'] > 0:
210+
comments = client.get_comments(asset['id'])
211+
my_comment_list = [comment for comment in comments.results]
212+
for object in my_comment_list:
213+
object.update({'parent_id':parent_id})
214+
object.update({'name':asset_name})
215+
comment_list.append(my_comment_list)
216+
217+
def get_all_project_comments(root_asset_id, token):
218+
"""
219+
Get all project comments for an asset.
220+
"""
221+
222+
comment_list = []
223+
client = FrameioClient(token)
224+
225+
all_comments(client, root_asset_id, comment_list)
226+
227+
return comment_list
228+
174229
def create_asset(self, parent_asset_id, **kwargs):
175230
"""
176231
Create an asset.

0 commit comments

Comments
 (0)