Merge pull request 'export-direction-fix: убрал обязательный для первой формы direction при экспорте формы' (#33) from export-direction-fix into test
Reviewed-on: #33 Reviewed-by: Raykov-MS <RaykovMS@avt.rshb.ru>
This commit is contained in:
commit
3bf44c50d4
@ -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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user