fix(task2): import templates must not import sample data

This commit is contained in:
Atharv1705
2026-11-17 17:45:27 +05:30
parent 041a4075dd
commit 026da64e71
5 changed files with 136 additions and 22 deletions
+11 -5
View File
@@ -69,7 +69,7 @@ def build_import_template_xlsx(db: Session) -> BytesIO:
cell.border = _HEADER_BORDER
ws.row_dimensions[1].height = 26
ws.views.sheetView[0].showGridLines = True
ws.auto_filter.ref = f"A1:{get_column_letter(len(IMPORT_COLUMNS))}2"
ws.auto_filter.ref = f"A1:{get_column_letter(len(IMPORT_COLUMNS))}1"
ws.freeze_panes = "A2"
departments = (
@@ -125,11 +125,17 @@ def build_import_template_xlsx(db: Session) -> BytesIO:
"false",
"Sample row - replace or remove before import",
]
for col_idx, val in enumerate(sample_row, start=1):
ws.cell(row=2, column=col_idx, value=val)
_auto_fit_columns(ws)
# Sheet 2: Master Reference
# Sheet 2: Example
ws_ex = wb.create_sheet(title="Example")
ws_ex.views.sheetView[0].showGridLines = True
ws_ex.cell(row=1, column=1, value="Example only - this sheet is ignored on import")
for col_idx, val in enumerate(sample_row, start=1):
ws_ex.cell(row=2, column=col_idx, value=val)
_auto_fit_columns(ws_ex)
# Sheet 3: Master Reference
ref = wb.create_sheet(title="Master Reference")
ref.row_dimensions[1].height = 26
ref.views.sheetView[0].showGridLines = True
@@ -272,7 +278,7 @@ def _extract_rows(filename: str, content: bytes) -> list[tuple[int, dict[str, An
detail="Invalid Excel file. Please download and use the import template.",
code="INVALID_FILE_TYPE",
) from exc
ws = wb["Assets"] if "Assets" in wb.sheetnames else wb.active
ws = wb.worksheets[0]
header_cells = next(ws.iter_rows(min_row=1, max_row=1, values_only=True), None)
if not header_cells:
return []