Commit ·
4e32e9d
1
Parent(s): 5cbfc1d
fix: updateItem リクエストに必須の location パラメータ(インデックス)を指定するように修正
Browse files- utils/google_forms_api.py +10 -4
utils/google_forms_api.py
CHANGED
|
@@ -266,16 +266,17 @@ def create_google_form(
|
|
| 266 |
body={"requests": requests}
|
| 267 |
).execute()
|
| 268 |
|
| 269 |
-
# 3. 遷移先IDを設定する (ステップ2: 作成されたアイテムを取得してIDを特定)
|
| 270 |
form_info = forms_service.forms().get(formId=form_id).execute()
|
| 271 |
items = form_info.get("items", [])
|
| 272 |
|
| 273 |
date_avail_q_ids = {}
|
| 274 |
date_avail_item_ids = {}
|
|
|
|
| 275 |
date_avail_section_ids = {}
|
| 276 |
note_section_id = None
|
| 277 |
|
| 278 |
-
for item in items:
|
| 279 |
title = item.get("title", "")
|
| 280 |
|
| 281 |
if title == "その他連絡事項" and "pageBreakItem" in item:
|
|
@@ -295,15 +296,17 @@ def create_google_form(
|
|
| 295 |
elif title == f"{date_label}は出勤できますか?" and "questionItem" in item:
|
| 296 |
date_avail_q_ids[ds] = item["questionItem"]["question"]["questionId"]
|
| 297 |
date_avail_item_ids[ds] = item["itemId"]
|
|
|
|
| 298 |
|
| 299 |
# 4. 2回目の batchUpdate で「いいえ(休み)」の遷移先 (goToSectionId) を設定
|
| 300 |
-
# ※ Forms API
|
| 301 |
update_requests = []
|
| 302 |
for i, d in enumerate(dates):
|
| 303 |
ds = d.isoformat()
|
| 304 |
q_id = date_avail_q_ids.get(ds)
|
| 305 |
item_id = date_avail_item_ids.get(ds)
|
| 306 |
-
|
|
|
|
| 307 |
continue
|
| 308 |
|
| 309 |
if i < len(dates) - 1:
|
|
@@ -332,6 +335,9 @@ def create_google_form(
|
|
| 332 |
}
|
| 333 |
}
|
| 334 |
},
|
|
|
|
|
|
|
|
|
|
| 335 |
"updateMask": "questionItem.question.choiceQuestion.options"
|
| 336 |
}
|
| 337 |
})
|
|
|
|
| 266 |
body={"requests": requests}
|
| 267 |
).execute()
|
| 268 |
|
| 269 |
+
# 3. 遷移先IDを設定する (ステップ2: 作成されたアイテムを取得してIDとインデックスを特定)
|
| 270 |
form_info = forms_service.forms().get(formId=form_id).execute()
|
| 271 |
items = form_info.get("items", [])
|
| 272 |
|
| 273 |
date_avail_q_ids = {}
|
| 274 |
date_avail_item_ids = {}
|
| 275 |
+
date_avail_item_indexes = {}
|
| 276 |
date_avail_section_ids = {}
|
| 277 |
note_section_id = None
|
| 278 |
|
| 279 |
+
for idx, item in enumerate(items):
|
| 280 |
title = item.get("title", "")
|
| 281 |
|
| 282 |
if title == "その他連絡事項" and "pageBreakItem" in item:
|
|
|
|
| 296 |
elif title == f"{date_label}は出勤できますか?" and "questionItem" in item:
|
| 297 |
date_avail_q_ids[ds] = item["questionItem"]["question"]["questionId"]
|
| 298 |
date_avail_item_ids[ds] = item["itemId"]
|
| 299 |
+
date_avail_item_indexes[ds] = idx
|
| 300 |
|
| 301 |
# 4. 2回目の batchUpdate で「いいえ(休み)」の遷移先 (goToSectionId) を設定
|
| 302 |
+
# ※ Forms API の updateItem リクエストには location が必須です。
|
| 303 |
update_requests = []
|
| 304 |
for i, d in enumerate(dates):
|
| 305 |
ds = d.isoformat()
|
| 306 |
q_id = date_avail_q_ids.get(ds)
|
| 307 |
item_id = date_avail_item_ids.get(ds)
|
| 308 |
+
item_idx = date_avail_item_indexes.get(ds)
|
| 309 |
+
if not q_id or not item_id or item_idx is None:
|
| 310 |
continue
|
| 311 |
|
| 312 |
if i < len(dates) - 1:
|
|
|
|
| 335 |
}
|
| 336 |
}
|
| 337 |
},
|
| 338 |
+
"location": {
|
| 339 |
+
"index": item_idx
|
| 340 |
+
},
|
| 341 |
"updateMask": "questionItem.question.choiceQuestion.options"
|
| 342 |
}
|
| 343 |
})
|