m1m02530125 commited on
Commit
5cbfc1d
·
1 Parent(s): ca861f0

fix: Forms API v1 のスキーマに準拠するため updateQuestion を updateItem に修正

Browse files
Files changed (1) hide show
  1. utils/google_forms_api.py +20 -11
utils/google_forms_api.py CHANGED
@@ -271,6 +271,7 @@ def create_google_form(
271
  items = form_info.get("items", [])
272
 
273
  date_avail_q_ids = {}
 
274
  date_avail_section_ids = {}
275
  note_section_id = None
276
 
@@ -293,13 +294,16 @@ def create_google_form(
293
  date_avail_section_ids[ds] = item["itemId"]
294
  elif title == f"{date_label}は出勤できますか?" and "questionItem" in item:
295
  date_avail_q_ids[ds] = item["questionItem"]["question"]["questionId"]
 
296
 
297
  # 4. 2回目の batchUpdate で「いいえ(休み)」の遷移先 (goToSectionId) を設定
 
298
  update_requests = []
299
  for i, d in enumerate(dates):
300
  ds = d.isoformat()
301
  q_id = date_avail_q_ids.get(ds)
302
- if not q_id:
 
303
  continue
304
 
305
  if i < len(dates) - 1:
@@ -312,18 +316,23 @@ def create_google_form(
312
  continue
313
 
314
  update_requests.append({
315
- "updateQuestion": {
316
- "question": {
317
- "questionId": q_id,
318
- "choiceQuestion": {
319
- "type": "RADIO",
320
- "options": [
321
- {"value": "はい(出勤可能)"},
322
- {"value": "いいえ(休み)", "goToSectionId": next_section_id}
323
- ]
 
 
 
 
 
324
  }
325
  },
326
- "updateMask": "choiceQuestion.options"
327
  }
328
  })
329
 
 
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
 
 
294
  date_avail_section_ids[ds] = item["itemId"]
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 には updateQuestion リクエストはなく、updateItem リクエストを使用する必要があります。
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
+ if not q_id or not item_id:
307
  continue
308
 
309
  if i < len(dates) - 1:
 
316
  continue
317
 
318
  update_requests.append({
319
+ "updateItem": {
320
+ "item": {
321
+ "itemId": item_id,
322
+ "questionItem": {
323
+ "question": {
324
+ "questionId": q_id,
325
+ "choiceQuestion": {
326
+ "type": "RADIO",
327
+ "options": [
328
+ {"value": "はい(出勤可能)"},
329
+ {"value": "いいえ(休み)", "goToSectionId": next_section_id}
330
+ ]
331
+ }
332
+ }
333
  }
334
  },
335
+ "updateMask": "questionItem.question.choiceQuestion.options"
336
  }
337
  })
338