export-direction-fix: убрал обязательный для первой формы direction при экспорте формы

This commit is contained in:
tsygankoviva 2026-06-04 17:29:59 +03:00
parent 14d2271eb9
commit 71deb55485

View File

@ -169,13 +169,28 @@ class ExportService:
form = await self._get_form_for_export(form_id=form_id, current_user=current_user)
sheets = self._resolve_requested_sheets(form=form, requested_sheet=sheet)
self._validate_sections_for_form(form=form, sections=sections)
plans = self._build_sheet_plans(
form=form,
sheets=sheets,
direction=direction,
sections=sections,
ignore_non_applicable_query_params=ignore_non_applicable_query_params,
)
if direction:
plans = self._build_sheet_plans(
form=form,
sheets=sheets,
direction=direction,
sections=sections,
ignore_non_applicable_query_params=ignore_non_applicable_query_params,
)
else:
sheets_by_directions = self._resolve_sheets_by_directions(form=form, requested_sheet=sheet)
plans = []
for dr, shts in sheets_by_directions.items():
plans += self._build_sheet_plans(
form=form,
sheets=shts,
direction=dr,
sections=sections,
ignore_non_applicable_query_params=ignore_non_applicable_query_params,
)
workbook = self._create_workbook_with_metadata(form=form)
exported_sheets = 0
@ -294,6 +309,18 @@ class ExportService:
if requested_sheet:
return [requested_sheet]
return list(form.form_type.sheet_list)
def _resolve_sheets_by_directions(self, form: Any, requested_sheet: str | None) -> dict[str | None, str]:
result = {}
for sheet in form.form_type.sheet_list_with_directions:
if requested_sheet and sheet["sheet_name"] != requested_sheet:
continue
if sheet["direction"] in result:
result[sheet["direction"]].append(sheet["sheet_name"])
else:
result[sheet["direction"]] = [sheet["sheet_name"]]
return result
@staticmethod
def _validate_sections_for_form(form: Any, sections: list[str] | None) -> None: