ichieh commited on
Commit
bf2d715
·
1 Parent(s): 19595ec

Include is_table_leader field in backup and restore operations

Browse files
Files changed (1) hide show
  1. app.py +9 -10
app.py CHANGED
@@ -246,6 +246,7 @@ def backup_settings():
246
  'introduction': p.introduction,
247
  'table_id': p.table_id,
248
  'seat_number': p.seat_number,
 
249
  'created_at': p.created_at.strftime('%Y-%m-%d %H:%M:%S')
250
  } for p in participants]
251
  })
@@ -300,21 +301,18 @@ def restore_settings():
300
  # 如果都失敗,使用當前時間
301
  created_at = datetime.utcnow()
302
 
303
- # 確保 table_id 存在且有效
304
- old_table_id = str(participant_data['table_id']) # 將 id 轉換為字串
305
  new_table_id = tables.get(old_table_id)
306
 
307
- if new_table_id is None:
308
- print(f'Warning: Invalid table_id {old_table_id} for participant {participant_data["nickname"]}')
309
-
310
  participant = Participant(
311
  nickname=participant_data['nickname'],
312
  email=participant_data['email'],
313
- fb_link=participant_data.get('fb_link'),
314
- introduction=participant_data.get('introduction'),
315
- table_id=new_table_id, # 可能為 None
316
- seat_number=participant_data.get('seat_number'),
317
- is_table_leader=participant_data.get('is_table_leader', False),
318
  created_at=created_at
319
  )
320
  db.session.add(participant)
@@ -463,6 +461,7 @@ def register():
463
  'introduction': p.introduction,
464
  'table_id': p.table_id,
465
  'seat_number': p.seat_number,
 
466
  'created_at': p.created_at.strftime('%Y-%m-%d %H:%M:%S')
467
  } for p in all_participants]
468
  })
 
246
  'introduction': p.introduction,
247
  'table_id': p.table_id,
248
  'seat_number': p.seat_number,
249
+ 'is_table_leader': p.is_table_leader,
250
  'created_at': p.created_at.strftime('%Y-%m-%d %H:%M:%S')
251
  } for p in participants]
252
  })
 
301
  # 如果都失敗,使用當前時間
302
  created_at = datetime.utcnow()
303
 
304
+ # 取得新的 table_id
305
+ old_table_id = str(participant_data['table_id'])
306
  new_table_id = tables.get(old_table_id)
307
 
 
 
 
308
  participant = Participant(
309
  nickname=participant_data['nickname'],
310
  email=participant_data['email'],
311
+ fb_link=participant_data.get('fb_link', ''), # 使用 get 避免缺少欄位
312
+ introduction=participant_data.get('introduction', ''),
313
+ table_id=new_table_id,
314
+ seat_number=participant_data['seat_number'],
315
+ is_table_leader=participant_data.get('is_table_leader', False), # 使用 get 避免缺少欄位
316
  created_at=created_at
317
  )
318
  db.session.add(participant)
 
461
  'introduction': p.introduction,
462
  'table_id': p.table_id,
463
  'seat_number': p.seat_number,
464
+ 'is_table_leader': p.is_table_leader,
465
  'created_at': p.created_at.strftime('%Y-%m-%d %H:%M:%S')
466
  } for p in all_participants]
467
  })