feat: 修改考试记录导出功能

This commit is contained in:
TianyangZhang 2025-10-23 15:51:50 +08:00
parent 1800d53edd
commit 5b8d4c3788
1 changed files with 10 additions and 5 deletions

View File

@ -17,10 +17,11 @@ def export_question(questions:object):
row = ws1.row_dimensions[1] row = ws1.row_dimensions[1]
row.font = Font(bold=True) row.font = Font(bold=True)
for i in questions: for i in questions:
if not i.questioncat: try:
print(f"没有分类{i.name}") ws1.append([i.questioncat.name, i.type, i.name, json.dumps(i.options, ensure_ascii=False), ''.join(sorted(i.right)), i.resolution])
except AttributeError as e:
print(f"跳过一条记录,原因: {e}, 记录ID/类型: {getattr(i, 'id', '未知')}/{getattr(i, 'type', '未知')}")
continue continue
ws1.append([i.questioncat.name, i.type, i.name, json.dumps(i.options, ensure_ascii=False), ''.join(sorted(i.right)), i.resolution])
filename = 'questions' + datetime.now().strftime("%Y%m%d%H%M%S") +'.xlsx' filename = 'questions' + datetime.now().strftime("%Y%m%d%H%M%S") +'.xlsx'
path = '/media/temp/' path = '/media/temp/'
full_path = settings.BASE_DIR + '/media/temp/' full_path = settings.BASE_DIR + '/media/temp/'
@ -42,8 +43,12 @@ def export_record(records:object):
row = ws1.row_dimensions[1] row = ws1.row_dimensions[1]
row.font = Font(bold=True) row.font = Font(bold=True)
for i in records: for i in records:
tookformat = get_took_format(i.took) try:
ws1.append([i.type, i.create_by.name, i.is_pass, i.score, i.total_score, str(tookformat), str(i.start_time), i.belong_dept.name]) tookformat = get_took_format(i.took)
ws1.append([i.type, i.create_by.name, i.is_pass, i.score, i.total_score, str(tookformat), str(i.start_time), i.belong_dept.name])
except AttributeError as e:
print(f"跳过一条记录,原因: {e}, 记录ID/类型: {getattr(i, 'id', '未知')}/{getattr(i, 'type', '未知')}")
continue
filename = 'records' + datetime.now().strftime("%Y%m%d%H%M%S") +'.xlsx' filename = 'records' + datetime.now().strftime("%Y%m%d%H%M%S") +'.xlsx'
path = '/media/temp/' path = '/media/temp/'
full_path = settings.BASE_DIR + '/media/temp/' full_path = settings.BASE_DIR + '/media/temp/'