]> git.cworth.org Git - turbot/commitdiff
Rename each sheet we copy from the template
authorCarl Worth <cworth@cworth.org>
Sat, 9 Jan 2021 14:29:42 +0000 (06:29 -0800)
committerCarl Worth <cworth@cworth.org>
Sat, 9 Jan 2021 14:44:58 +0000 (06:44 -0800)
To get rid of the silly "Copy of" text that we don't need.

turbot/puzzle.py
turbot/sheets.py

index 1dbea5d74906c447b3e6b09df70758f4379389d5..f2816acb5b42b5903c3587060bc03680e706d670 100644 (file)
@@ -290,7 +290,7 @@ def puzzle_update_channel_and_sheet(turb, puzzle, old_puzzle=None):
         old_sheet_name = puzzle_sheet_name(old_puzzle)
 
     if sheet_name != old_sheet_name:
         old_sheet_name = puzzle_sheet_name(old_puzzle)
 
     if sheet_name != old_sheet_name:
-        turbot.sheets.renameSheet(turb, puzzle['sheet_url'], sheet_name)
+        turbot.sheets.rename_spreadsheet(turb, puzzle['sheet_url'], sheet_name)
 
     # Compute the Slack channel name and set it if it has changed
     channel_name = puzzle_channel_name(puzzle)
 
     # Compute the Slack channel name and set it if it has changed
     channel_name = puzzle_channel_name(puzzle)
index 9f8b7c3e0d38eabb0fd08332b684ea39789fea66..ff8b1423f3385c8bdb700ccbbbb14aa3c7c5d7a5 100644 (file)
@@ -74,16 +74,36 @@ def sheets_create_for_puzzle(turb, puzzle):
 
     for sheet in response["sheets"]:
         if sheet["properties"]["title"] in PUZZLE_TEMPLATE_SHEETS:
 
     for sheet in response["sheets"]:
         if sheet["properties"]["title"] in PUZZLE_TEMPLATE_SHEETS:
-            turb.sheets.sheets().copyTo(spreadsheetId=PUZZLE_TEMPLATE_ID,
-                                        sheetId=sheet["properties"]["sheetId"],
-                                        body={
-                                            "destinationSpreadsheetId":
-                                            new_sheet['id']
-                                        }).execute()
+            res = turb.sheets.sheets().copyTo(
+                spreadsheetId=PUZZLE_TEMPLATE_ID,
+                sheetId=sheet["properties"]["sheetId"],
+                body={
+                    "destinationSpreadsheetId": new_sheet['id']
+                }).execute()
+            rename_sheet(turb, new_sheet['id'], res['sheetId'],
+                         sheet["properties"]["title"])
 
     return new_sheet
 
 
     return new_sheet
 
-def renameSheet(turb, url, newName):
+def rename_sheet(turb, spreadsheet_id, sheet_id, name):
+
+    body = {
+        'requests': [{
+            'updateSheetProperties': {
+                'properties': {
+                    'sheetId': sheet_id,
+                    'title': name
+                },
+                'fields': 'title'
+            }
+        }]
+    }
+
+    turb.sheets.batchUpdate(spreadsheetId=spreadsheet_id,
+                            body=body
+                            ).execute()
+
+def rename_spreadsheet(turb, url, newName):
     id = extractIdFromSheetUrl(url)
     requests = []
     requests.append({
     id = extractIdFromSheetUrl(url)
     requests = []
     requests.append({