m1m02530125 commited on
Commit
0976355
·
1 Parent(s): 4e32e9d

fix: ラジオボタンのすべての選択肢に goToSectionId を明示的に設定して Google API 側のバリデーションエラーを解決

Browse files
Files changed (1) hide show
  1. utils/google_forms_api.py +8 -4
utils/google_forms_api.py CHANGED
@@ -274,6 +274,7 @@ def create_google_form(
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):
@@ -297,16 +298,19 @@ def create_google_form(
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:
@@ -328,7 +332,7 @@ def create_google_form(
328
  "choiceQuestion": {
329
  "type": "RADIO",
330
  "options": [
331
- {"value": "はい(出勤可能)"},
332
  {"value": "いいえ(休み)", "goToSectionId": next_section_id}
333
  ]
334
  }
 
274
  date_avail_item_ids = {}
275
  date_avail_item_indexes = {}
276
  date_avail_section_ids = {}
277
+ date_detail_section_ids = {}
278
  note_section_id = None
279
 
280
  for idx, item in enumerate(items):
 
298
  date_avail_q_ids[ds] = item["questionItem"]["question"]["questionId"]
299
  date_avail_item_ids[ds] = item["itemId"]
300
  date_avail_item_indexes[ds] = idx
301
+ elif title == f"{date_label} 希望時間帯選択" and "pageBreakItem" in item:
302
+ date_detail_section_ids[ds] = item["itemId"]
303
 
304
+ # 4. 2回目の batchUpdate で「はい(出勤可能)」と「いいえ(休み)」両方の遷移先 (goToSectionId) を設定
305
+ # ※ Google Forms API のラジオボタン分岐設定では、「すべての選択肢にジャンプ先を指定する」か「いずれにも指定しない」のどちらかでなければエラーになります。
306
  update_requests = []
307
  for i, d in enumerate(dates):
308
  ds = d.isoformat()
309
  q_id = date_avail_q_ids.get(ds)
310
  item_id = date_avail_item_ids.get(ds)
311
  item_idx = date_avail_item_indexes.get(ds)
312
+ detail_section_id = date_detail_section_ids.get(ds)
313
+ if not q_id or not item_id or item_idx is None or not detail_section_id:
314
  continue
315
 
316
  if i < len(dates) - 1:
 
332
  "choiceQuestion": {
333
  "type": "RADIO",
334
  "options": [
335
+ {"value": "はい(出勤可能)", "goToSectionId": detail_section_id},
336
  {"value": "いいえ(休み)", "goToSectionId": next_section_id}
337
  ]
338
  }