feat: 修改考试记录导出功能
This commit is contained in:
parent
1800d53edd
commit
5b8d4c3788
|
|
@ -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}")
|
|
||||||
continue
|
|
||||||
ws1.append([i.questioncat.name, i.type, i.name, json.dumps(i.options, ensure_ascii=False), ''.join(sorted(i.right)), i.resolution])
|
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
|
||||||
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:
|
||||||
|
try:
|
||||||
tookformat = get_took_format(i.took)
|
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])
|
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/'
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue