11
11
from tableauserverclient .server .query import QuerySet
12
12
13
13
from tableauserverclient .server .endpoint .endpoint import QuerysetEndpoint , api , parameter_added_in
14
- from tableauserverclient .server .endpoint .exceptions import InternalServerError , MissingRequiredFieldError
14
+ from tableauserverclient .server .endpoint .exceptions import (
15
+ InternalServerError ,
16
+ MissingRequiredFieldError ,
17
+ UnsupportedAttributeError ,
18
+ )
15
19
from tableauserverclient .server .endpoint .permissions_endpoint import _PermissionsEndpoint
16
20
from tableauserverclient .server .endpoint .resource_tagger import TaggingMixin
17
21
34
38
35
39
if TYPE_CHECKING :
36
40
from tableauserverclient .server import Server
37
- from tableauserverclient .server .request_options import RequestOptions
41
+ from tableauserverclient .server .request_options import RequestOptions , PDFRequestOptions , PPTXRequestOptions
38
42
from tableauserverclient .models import DatasourceItem
39
43
from tableauserverclient .server .endpoint .schedules_endpoint import AddResponse
40
44
@@ -472,11 +476,12 @@ def _get_workbook_connections(
472
476
connections = ConnectionItem .from_response (server_response .content , self .parent_srv .namespace )
473
477
return connections
474
478
475
- # Get the pdf of the entire workbook if its tabs are enabled, pdf of the default view if its tabs are disabled
476
479
@api (version = "3.4" )
477
- def populate_pdf (self , workbook_item : WorkbookItem , req_options : Optional ["RequestOptions " ] = None ) -> None :
480
+ def populate_pdf (self , workbook_item : WorkbookItem , req_options : Optional ["PDFRequestOptions " ] = None ) -> None :
478
481
"""
479
- Populates the PDF for the specified workbook item.
482
+ Populates the PDF for the specified workbook item. Get the pdf of the
483
+ entire workbook if its tabs are enabled, pdf of the default view if its
484
+ tabs are disabled.
480
485
481
486
This method populates a PDF with image(s) of the workbook view(s) you
482
487
specify.
@@ -488,7 +493,7 @@ def populate_pdf(self, workbook_item: WorkbookItem, req_options: Optional["Reque
488
493
workbook_item : WorkbookItem
489
494
The workbook item to populate the PDF for.
490
495
491
- req_options : RequestOptions , optional
496
+ req_options : PDFRequestOptions , optional
492
497
(Optional) You can pass in request options to specify the page type
493
498
and orientation of the PDF content, as well as the maximum age of
494
499
the PDF rendered on the server. See PDFRequestOptions class for more
@@ -510,17 +515,26 @@ def populate_pdf(self, workbook_item: WorkbookItem, req_options: Optional["Reque
510
515
def pdf_fetcher () -> bytes :
511
516
return self ._get_wb_pdf (workbook_item , req_options )
512
517
518
+ if not self .parent_srv .check_at_least_version ("3.23" ) and req_options is not None :
519
+ if req_options .view_filters or req_options .view_parameters :
520
+ raise UnsupportedAttributeError ("view_filters and view_parameters are only supported in 3.23+" )
521
+
522
+ if req_options .viz_height or req_options .viz_width :
523
+ raise UnsupportedAttributeError ("viz_height and viz_width are only supported in 3.23+" )
524
+
513
525
workbook_item ._set_pdf (pdf_fetcher )
514
526
logger .info (f"Populated pdf for workbook (ID: { workbook_item .id } )" )
515
527
516
- def _get_wb_pdf (self , workbook_item : WorkbookItem , req_options : Optional ["RequestOptions " ]) -> bytes :
528
+ def _get_wb_pdf (self , workbook_item : WorkbookItem , req_options : Optional ["PDFRequestOptions " ]) -> bytes :
517
529
url = f"{ self .baseurl } /{ workbook_item .id } /pdf"
518
530
server_response = self .get_request (url , req_options )
519
531
pdf = server_response .content
520
532
return pdf
521
533
522
534
@api (version = "3.8" )
523
- def populate_powerpoint (self , workbook_item : WorkbookItem , req_options : Optional ["RequestOptions" ] = None ) -> None :
535
+ def populate_powerpoint (
536
+ self , workbook_item : WorkbookItem , req_options : Optional ["PPTXRequestOptions" ] = None
537
+ ) -> None :
524
538
"""
525
539
Populates the PowerPoint for the specified workbook item.
526
540
@@ -561,7 +575,7 @@ def pptx_fetcher() -> bytes:
561
575
workbook_item ._set_powerpoint (pptx_fetcher )
562
576
logger .info (f"Populated powerpoint for workbook (ID: { workbook_item .id } )" )
563
577
564
- def _get_wb_pptx (self , workbook_item : WorkbookItem , req_options : Optional ["RequestOptions " ]) -> bytes :
578
+ def _get_wb_pptx (self , workbook_item : WorkbookItem , req_options : Optional ["PPTXRequestOptions " ]) -> bytes :
565
579
url = f"{ self .baseurl } /{ workbook_item .id } /powerpoint"
566
580
server_response = self .get_request (url , req_options )
567
581
pptx = server_response .content
0 commit comments