11import logging
22
3- from typing import Union
3+ from typing import TypedDict , Union
44from defusedxml .ElementTree import fromstring
5-
6- from tableauserverclient .models .tableau_types import TableauItem
5+ from tableauserverclient .models .collection_item import CollectionItem
76from tableauserverclient .models .datasource_item import DatasourceItem
87from tableauserverclient .models .flow_item import FlowItem
98from tableauserverclient .models .project_item import ProjectItem
1312
1413from tableauserverclient .helpers .logging import logger
1514
16- FavoriteType = dict [
17- str ,
18- list [TableauItem ],
19- ]
15+
16+ class FavoriteType (TypedDict ):
17+ collections : list [CollectionItem ]
18+ datasources : list [DatasourceItem ]
19+ flows : list [FlowItem ]
20+ projects : list [ProjectItem ]
21+ metrics : list [MetricItem ]
22+ views : list [ViewItem ]
23+ workbooks : list [WorkbookItem ]
2024
2125
2226class FavoriteItem :
2327 @classmethod
2428 def from_response (cls , xml : Union [str , bytes ], namespace : dict ) -> FavoriteType :
2529 favorites : FavoriteType = {
30+ "collections" : [],
2631 "datasources" : [],
2732 "flows" : [],
2833 "projects" : [],
@@ -32,6 +37,7 @@ def from_response(cls, xml: Union[str, bytes], namespace: dict) -> FavoriteType:
3237 }
3338 parsed_response = fromstring (xml )
3439
40+ collections_xml = parsed_response .findall (".//t:favorite/t:collection" , namespace )
3541 datasources_xml = parsed_response .findall (".//t:favorite/t:datasource" , namespace )
3642 flows_xml = parsed_response .findall (".//t:favorite/t:flow" , namespace )
3743 metrics_xml = parsed_response .findall (".//t:favorite/t:metric" , namespace )
@@ -40,13 +46,14 @@ def from_response(cls, xml: Union[str, bytes], namespace: dict) -> FavoriteType:
4046 workbooks_xml = parsed_response .findall (".//t:favorite/t:workbook" , namespace )
4147
4248 logger .debug (
43- "ds: {}, flows: {}, metrics: {}, projects: {}, views: {}, wbs: {}" .format (
49+ "ds: {}, flows: {}, metrics: {}, projects: {}, views: {}, wbs: {}, collections: {} " .format (
4450 len (datasources_xml ),
4551 len (flows_xml ),
4652 len (metrics_xml ),
4753 len (projects_xml ),
4854 len (views_xml ),
4955 len (workbooks_xml ),
56+ len (collections_xml ),
5057 )
5158 )
5259 for datasource in datasources_xml :
@@ -85,5 +92,11 @@ def from_response(cls, xml: Union[str, bytes], namespace: dict) -> FavoriteType:
8592 logger .debug (fav_workbook )
8693 favorites ["workbooks" ].append (fav_workbook )
8794
95+ for collection in collections_xml :
96+ fav_collection = CollectionItem .from_xml (collection , namespace )
97+ if fav_collection :
98+ logger .debug (fav_collection )
99+ favorites ["collections" ].append (fav_collection )
100+
88101 logger .debug (favorites )
89102 return favorites
0 commit comments