1111from tableauserverclient .server .query import QuerySet
1212
1313from 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+ )
1519from tableauserverclient .server .endpoint .permissions_endpoint import _PermissionsEndpoint
1620from tableauserverclient .server .endpoint .resource_tagger import TaggingMixin
1721
3438
3539if TYPE_CHECKING :
3640 from tableauserverclient .server import Server
37- from tableauserverclient .server .request_options import RequestOptions
41+ from tableauserverclient .server .request_options import RequestOptions , PDFRequestOptions , PPTXRequestOptions
3842 from tableauserverclient .models import DatasourceItem
3943 from tableauserverclient .server .endpoint .schedules_endpoint import AddResponse
4044
@@ -472,11 +476,12 @@ def _get_workbook_connections(
472476 connections = ConnectionItem .from_response (server_response .content , self .parent_srv .namespace )
473477 return connections
474478
475- # Get the pdf of the entire workbook if its tabs are enabled, pdf of the default view if its tabs are disabled
476479 @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 :
478481 """
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.
480485
481486 This method populates a PDF with image(s) of the workbook view(s) you
482487 specify.
@@ -488,7 +493,7 @@ def populate_pdf(self, workbook_item: WorkbookItem, req_options: Optional["Reque
488493 workbook_item : WorkbookItem
489494 The workbook item to populate the PDF for.
490495
491- req_options : RequestOptions , optional
496+ req_options : PDFRequestOptions , optional
492497 (Optional) You can pass in request options to specify the page type
493498 and orientation of the PDF content, as well as the maximum age of
494499 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
510515 def pdf_fetcher () -> bytes :
511516 return self ._get_wb_pdf (workbook_item , req_options )
512517
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+
513525 workbook_item ._set_pdf (pdf_fetcher )
514526 logger .info (f"Populated pdf for workbook (ID: { workbook_item .id } )" )
515527
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 :
517529 url = f"{ self .baseurl } /{ workbook_item .id } /pdf"
518530 server_response = self .get_request (url , req_options )
519531 pdf = server_response .content
520532 return pdf
521533
522534 @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 :
524538 """
525539 Populates the PowerPoint for the specified workbook item.
526540
@@ -561,7 +575,7 @@ def pptx_fetcher() -> bytes:
561575 workbook_item ._set_powerpoint (pptx_fetcher )
562576 logger .info (f"Populated powerpoint for workbook (ID: { workbook_item .id } )" )
563577
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 :
565579 url = f"{ self .baseurl } /{ workbook_item .id } /powerpoint"
566580 server_response = self .get_request (url , req_options )
567581 pptx = server_response .content
0 commit comments