diff --git a/server/apps/exam/exports.py b/server/apps/exam/exports.py index f27b202..dc0f05d 100644 --- a/server/apps/exam/exports.py +++ b/server/apps/exam/exports.py @@ -17,10 +17,11 @@ def export_question(questions:object): row = ws1.row_dimensions[1] row.font = Font(bold=True) for i in questions: - if not i.questioncat: - print(f"没有分类{i.name}") + try: + 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 - 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' path = '/media/temp/' full_path = settings.BASE_DIR + '/media/temp/' @@ -42,8 +43,12 @@ def export_record(records:object): row = ws1.row_dimensions[1] row.font = Font(bold=True) for i in records: - 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]) + try: + 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' path = '/media/temp/' full_path = settings.BASE_DIR + '/media/temp/'