11import copy
22from datetime import datetime
33from requests import Response
4- from typing import Callable , Optional
4+ from typing import TYPE_CHECKING , Callable , Optional , overload
55from collections .abc import Iterator
66
77from defusedxml .ElementTree import fromstring
88
99from tableauserverclient .datetime_helpers import parse_datetime
1010from tableauserverclient .models .exceptions import UnpopulatedPropertyError
11+ from tableauserverclient .models .location_item import LocationItem
1112from tableauserverclient .models .permissions_item import PermissionsRule
13+ from tableauserverclient .models .project_item import ProjectItem
1214from tableauserverclient .models .tag_item import TagItem
15+ from tableauserverclient .models .user_item import UserItem
16+
17+ if TYPE_CHECKING :
18+ from tableauserverclient .models .workbook_item import WorkbookItem
1319
1420
1521class ViewItem :
@@ -84,11 +90,18 @@ def __init__(self) -> None:
8490 self ._workbook_id : Optional [str ] = None
8591 self ._permissions : Optional [Callable [[], list [PermissionsRule ]]] = None
8692 self .tags : set [str ] = set ()
93+ self ._favorites_total : Optional [int ] = None
94+ self ._view_url_name : Optional [str ] = None
8795 self ._data_acceleration_config = {
8896 "acceleration_enabled" : None ,
8997 "acceleration_status" : None ,
9098 }
9199
100+ self ._owner : Optional [UserItem ] = None
101+ self ._project : Optional [ProjectItem ] = None
102+ self ._workbook : Optional ["WorkbookItem" ] = None
103+ self ._location : Optional [LocationItem ] = None
104+
92105 def __str__ (self ):
93106 return "<ViewItem {} '{}' contentUrl='{}' project={}>" .format (
94107 self ._id , self .name , self .content_url , self .project_id
@@ -190,6 +203,14 @@ def updated_at(self) -> Optional[datetime]:
190203 def workbook_id (self ) -> Optional [str ]:
191204 return self ._workbook_id
192205
206+ @property
207+ def view_url_name (self ) -> Optional [str ]:
208+ return self ._view_url_name
209+
210+ @property
211+ def favorites_total (self ) -> Optional [int ]:
212+ return self ._favorites_total
213+
193214 @property
194215 def data_acceleration_config (self ):
195216 return self ._data_acceleration_config
@@ -198,6 +219,22 @@ def data_acceleration_config(self):
198219 def data_acceleration_config (self , value ):
199220 self ._data_acceleration_config = value
200221
222+ @property
223+ def project (self ) -> Optional ["ProjectItem" ]:
224+ return self ._project
225+
226+ @property
227+ def workbook (self ) -> Optional ["WorkbookItem" ]:
228+ return self ._workbook
229+
230+ @property
231+ def owner (self ) -> Optional [UserItem ]:
232+ return self ._owner
233+
234+ @property
235+ def location (self ) -> Optional [LocationItem ]:
236+ return self ._location
237+
201238 @property
202239 def permissions (self ) -> list [PermissionsRule ]:
203240 if self ._permissions is None :
@@ -228,30 +265,43 @@ def from_xml(cls, view_xml, ns, workbook_id="") -> "ViewItem":
228265 workbook_elem = view_xml .find (".//t:workbook" , namespaces = ns )
229266 owner_elem = view_xml .find (".//t:owner" , namespaces = ns )
230267 project_elem = view_xml .find (".//t:project" , namespaces = ns )
231- tags_elem = view_xml .find (".// t:tags" , namespaces = ns )
268+ tags_elem = view_xml .find ("./t:tags" , namespaces = ns )
232269 data_acceleration_config_elem = view_xml .find (".//t:dataAccelerationConfig" , namespaces = ns )
233270 view_item ._created_at = parse_datetime (view_xml .get ("createdAt" , None ))
234271 view_item ._updated_at = parse_datetime (view_xml .get ("updatedAt" , None ))
235272 view_item ._id = view_xml .get ("id" , None )
236273 view_item ._name = view_xml .get ("name" , None )
237274 view_item ._content_url = view_xml .get ("contentUrl" , None )
238275 view_item ._sheet_type = view_xml .get ("sheetType" , None )
276+ view_item ._favorites_total = string_to_int (view_xml .get ("favoritesTotal" , None ))
277+ view_item ._view_url_name = view_xml .get ("viewUrlName" , None )
239278 if usage_elem is not None :
240279 total_view = usage_elem .get ("totalViewCount" , None )
241280 if total_view :
242281 view_item ._total_views = int (total_view )
243282 if owner_elem is not None :
283+ user = UserItem .from_xml (owner_elem , ns )
284+ view_item ._owner = user
244285 view_item ._owner_id = owner_elem .get ("id" , None )
245286 if project_elem is not None :
246- view_item ._project_id = project_elem .get ("id" , None )
287+ project_item = ProjectItem .from_xml (project_elem , ns )
288+ view_item ._project = project_item
289+ view_item ._project_id = project_item .id
247290 if workbook_id :
248291 view_item ._workbook_id = workbook_id
249292 elif workbook_elem is not None :
250- view_item ._workbook_id = workbook_elem .get ("id" , None )
293+ from tableauserverclient .models .workbook_item import WorkbookItem
294+
295+ workbook_item = WorkbookItem .from_xml (workbook_elem , ns )
296+ view_item ._workbook = workbook_item
297+ view_item ._workbook_id = workbook_item .id
251298 if tags_elem is not None :
252299 tags = TagItem .from_xml_element (tags_elem , ns )
253300 view_item .tags = tags
254301 view_item ._initial_tags = copy .copy (tags )
302+ if (location_elem := view_xml .find (".//t:location" , namespaces = ns )) is not None :
303+ location = LocationItem .from_xml (location_elem , ns )
304+ view_item ._location = location
255305 if data_acceleration_config_elem is not None :
256306 data_acceleration_config = parse_data_acceleration_config (data_acceleration_config_elem )
257307 view_item .data_acceleration_config = data_acceleration_config
@@ -274,3 +324,15 @@ def parse_data_acceleration_config(data_acceleration_elem):
274324
275325def string_to_bool (s : str ) -> bool :
276326 return s .lower () == "true"
327+
328+
329+ @overload
330+ def string_to_int (s : None ) -> None : ...
331+
332+
333+ @overload
334+ def string_to_int (s : str ) -> int : ...
335+
336+
337+ def string_to_int (s ):
338+ return int (s ) if s is not None else None
0 commit comments