1+ import io
12import logging
2- from typing import List , Optional , Tuple
3+ import os
4+ from typing import List , Optional , Tuple , Union
35
4- from .endpoint import QuerysetEndpoint , api
5- from .exceptions import MissingRequiredFieldError
6+ from tableauserverclient . server . endpoint .endpoint import QuerysetEndpoint , api
7+ from tableauserverclient . server . endpoint .exceptions import MissingRequiredFieldError
68from tableauserverclient .models import CustomViewItem , PaginationItem
79from tableauserverclient .server import RequestFactory , RequestOptions , ImageRequestOptions
810
1618update the name or owner of a custom view.
1719"""
1820
21+ FilePath = Union [str , os .PathLike ]
22+ FileObject = Union [io .BufferedReader , io .BytesIO ]
23+ FileObjectR = Union [io .BufferedReader , io .BytesIO ]
24+ FileObjectW = Union [io .BufferedWriter , io .BytesIO ]
25+ PathOrFileR = Union [FilePath , FileObjectR ]
26+ PathOrFileW = Union [FilePath , FileObjectW ]
27+ io_types_r = (io .BufferedReader , io .BytesIO )
28+ io_types_w = (io .BufferedWriter , io .BytesIO )
29+
1930
2031class CustomViews (QuerysetEndpoint [CustomViewItem ]):
2132 def __init__ (self , parent_srv ):
@@ -25,6 +36,10 @@ def __init__(self, parent_srv):
2536 def baseurl (self ) -> str :
2637 return "{0}/sites/{1}/customviews" .format (self .parent_srv .baseurl , self .parent_srv .site_id )
2738
39+ @property
40+ def expurl (self ) -> str :
41+ return f"{ self .parent_srv ._server_address } /api/exp/sites/{ self .parent_srv .site_id } /customviews"
42+
2843 """
2944 If the request has no filter parameters: Administrators will see all custom views.
3045 Other users will see only custom views that they own.
@@ -102,3 +117,16 @@ def delete(self, view_id: str) -> None:
102117 url = "{0}/{1}" .format (self .baseurl , view_id )
103118 self .delete_request (url )
104119 logger .info ("Deleted single custom view (ID: {0})" .format (view_id ))
120+
121+ @api (version = "3.21" )
122+ def download (self , view_item : CustomViewItem , file : PathOrFileW ) -> PathOrFileW :
123+ url = f"{ self .expurl } /{ view_item .id } /content"
124+ server_response = self .get_request (url )
125+ if isinstance (file , io_types_w ):
126+ file .write (server_response .content )
127+ return file
128+
129+ with open (file , "wb" ) as f :
130+ f .write (server_response .content )
131+
132+ return file
0 commit comments