@@ -30,6 +30,11 @@ def main():
3030 parser .add_argument (
3131 "--powerpoint" , "-ppt" , metavar = "FILENAME" , help = "filename (a .ppt file) to save the powerpoint deck"
3232 )
33+ parser .add_argument (
34+ "--delete" ,
35+ action = "store_true" ,
36+ help = "delete the last custom view on the site after the update/export demo" ,
37+ )
3338
3439 args = parser .parse_args ()
3540
@@ -60,6 +65,7 @@ def main():
6065 all_workbooks = list (TSC .Pager (server .workbooks ))
6166 print ([workbook .name for workbook in all_workbooks ])
6267
68+ custom_views = []
6369 if all_workbooks :
6470 # Pick one workbook from the list
6571 sample_workbook = all_workbooks [0 ]
@@ -117,23 +123,26 @@ def main():
117123
118124 # Get custom views. `.get()` only returns the first page;
119125 # use TSC.Pager to iterate every custom view on the site.
120- for c in TSC .Pager (server .custom_views ):
126+ custom_views = list (TSC .Pager (server .custom_views ))
127+ for c in custom_views :
121128 print (c )
122129
123- # for the last custom view in the list
130+ if custom_views :
131+ # For the last custom view in the list.
132+ c = custom_views [- 1 ]
124133
125- # update the name
126- # note that this will fail if the name is already changed to this value
127- changed : TSC .CustomViewItem (id = c .id , name = "I was updated by tsc" )
128- verified_change = server .custom_views .update (changed )
129- print (verified_change )
134+ # update the name
135+ # note that this will fail if the name is already changed to this value
136+ changed = TSC .CustomViewItem (id = c .id , name = "I was updated by tsc" )
137+ verified_change = server .custom_views .update (changed )
138+ print (verified_change )
130139
131- # export as image. Filters etc could be added here as usual
132- server .custom_views .populate_image (c )
133- filename = c .id + "-image-export.png"
134- with open (filename , "wb" ) as f :
135- f .write (c .image )
136- print ("saved to " + filename )
140+ # export as image. Filters etc could be added here as usual
141+ server .custom_views .populate_image (c )
142+ filename = c .id + "-image-export.png"
143+ with open (filename , "wb" ) as f :
144+ f .write (c .image )
145+ print ("saved to " + filename )
137146
138147 if args .powerpoint :
139148 # Populate workbook preview image
@@ -143,9 +152,12 @@ def main():
143152 print (f"\n Downloaded powerpoint of workbook to { os .path .abspath (args .powerpoint )} " )
144153
145154 if args .delete :
146- print (f"deleting { c .id } " )
147- unlucky = TSC .CustomViewItem (c .id )
148- server .custom_views .delete (unlucky .id )
155+ if not custom_views :
156+ print ("--delete requested but no custom views on this site; nothing to delete." )
157+ else :
158+ print (f"deleting { c .id } " )
159+ unlucky = TSC .CustomViewItem (c .id )
160+ server .custom_views .delete (unlucky .id )
149161
150162
151163if __name__ == "__main__" :
0 commit comments