From ee51d944119832b3272bf0bbd330066d6dd5d658 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Sat, 9 Jan 2021 06:29:42 -0800 Subject: [PATCH] Rename each sheet we copy from the template To get rid of the silly "Copy of" text that we don't need. --- turbot/puzzle.py | 2 +- turbot/sheets.py | 34 +++++++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/turbot/puzzle.py b/turbot/puzzle.py index 1dbea5d..f2816ac 100644 --- a/turbot/puzzle.py +++ b/turbot/puzzle.py @@ -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: - 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) diff --git a/turbot/sheets.py b/turbot/sheets.py index 9f8b7c3..ff8b142 100644 --- a/turbot/sheets.py +++ b/turbot/sheets.py @@ -74,16 +74,36 @@ def sheets_create_for_puzzle(turb, puzzle): 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 -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({ -- 2.43.0